Skip to content
Programmingoneonone
Programmingoneonone
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Seven-Segment Display problem solution

YASH PAL, 31 July 202411 February 2026
In this HackerEarth Seven-Segment Display problem solution, you all must have seen a seven-segment display. Alice got a number written in a seven-segment format where each segment was created used a matchstick.
Example: If Alice gets a number 123 so basically Alice used 12 matchsticks for this number. Alice is wondering what is the numerically largest value that she can generate by using at most the matchsticks that she currently possesses. Help Alice out by telling her that number.
hackerEarth Seven-Segment Display problem solution

HackerEarth Seven-Segment Display problem solution.

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
string s;
ll t,a[10];
void solve()
{
ll i,j,k;
cin>>t;
a[0]=a[6]=a[9]=6;
a[1]=2;
a[2]=a[3]=a[5]=5;
a[4]=4;
a[7]=3;
a[8]=7;
while(t--)
{
cin>>s;
ll val=0;
for(i=0;i<s.size();i++)
{
val+=a[s[i]-'0'];
}
if(val%2==1)
{
cout<<"7";
val-=3;
}
while(val>=2)
{
val-=2;
cout<<"1";
}
cout<<"n";
}
}
int main()
{

solve();
return 0;
}
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes