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

HackerEarth Seven-Segment Display problem solution

YASH PAL, 31 July 202413 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 *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

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