Given a positive integer N. The task is to find the maximum number that can be displayed on seven segment display using N segments.
Seven Segment Display: A seven-segment display (SSD), or seven-segment indicator, is a form of an electronic display device for displaying decimal numerals that is an alternative to the more complex dot matrix displays.
Input : N = 5 Output : 71 On 7-segment display, 71 will look like: _ | | | | Input : N = 4 Output : 11
Observe, the number having a greater number of digits than other numbers will be greater in value. So, we will try to make a number with maximum possible length (number of digits) using given ‘N’ segments.
Also observe, to increase the length of the number we will try to use less segment on each digit as possible. So, number ‘1’ use only 2 segments to represent a digit. No other digit use less than 2 segments.
So, in case N is even, the answer would be 1s N/2 number of time.
In case N is odd, we cannot use all segments if we make 1s N/2 number of time. Also, if we use 3 segments to make a digit of 7 and (N-3)/2 number of 1s, then the number formed will be greater in value than the number formed by N/2 number of 1s.
Below is the implementation of this approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Maximum number on 7-segment display using N segments : Recursive
- Find element using minimum segments in Seven Segment Display
- Check if mirror image of a number is same if displayed in seven segment display
- Maximum number of segments that can contain the given points
- Maximum number of parallelograms that can be made using the given length of line segments
- Maximum sum of the array after dividing it into three segments
- Partition an array such into maximum increasing segments
- Maximum possible intersection by moving centers of line segments
- Split the array into odd number of segments of odd lengths
- Count of ways to split a given number into prime segments
- Number of horizontal or vertical line segments to connect 3 points
- Minimum splits required to convert a number into prime segments
- Check if number can be displayed using seven segment led
- Minimum number of cuts required to make circle segments equal sized
- Maximize the given number by replacing a segment of digits with the alternate digits given
- Maximum number formed from array with K number of adjacent swaps allowed
- Find the largest number smaller than integer N with maximum number of set bits
- Largest number dividing maximum number of elements in the array
- Find the maximum number of composite summands of a number
- Find maximum number that can be formed using digits of a given number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.