Given a string str representing an integer and an integer led which is the count of LEDs available. The task is to check if it is possible to display the number using the given LEDs.
Note that a digit will be displayed as it is displayed on a 7 segment LED. If its possible to display the number then print Yes, otherwise print No.
Here’s an example of seven segment display:
Input: str = “999”, led = 5
9 takes 6 LEDs to be displayed. So 999 will require 18 LEDs
Since only 5 LEDs are available, it is not possible to display 999
Input: str = “123456789”, led = 43
Input: str = “123456789”, led = 20
Approach: Pre-compute the number of segments used by digits from 0 to 9 and store it. Now for each element of the string count the number of segments used by it. Now, if count ≤ led then print YES else print NO.
The number of segment used by digit:
0 -> 6
1 -> 2
2 -> 5
3 -> 5
4 -> 4
5 -> 5
6 -> 6
7 -> 3
8 -> 7
9 -> 6
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if mirror image of a number is same if displayed in seven segment display
- Minimum number of integers required such that each Segment contains at least one of them
- Maximum segment value after putting k breakpoints in a number
- Maximize the given number by replacing a segment of digits with the alternate digits given
- Maximum number that can be display on Seven Segment Display using N segments
- Check whether all the rotations of a given number is greater than or equal to the given number or not
- Check if a number is divisible by all prime divisors of another number
- Check if a large number is divisible by a number which is a power of 2
- Program to check whether a number is Proth number or not
- Check if the number is a Prime power number
- Check if a number with even number of digits is palindrome or not
- Segment Tree | Set 1 (Sum of given range)
- Check whether a given number is an ugly number or not
- Check Whether a number is Duck Number or not
- Check if a number is Triperfect Number
- How to check if a given number is Fibonacci number?
- Check if a number ends with another number or not
- Check if a number is a Krishnamurthy Number or not
- Check whether the given number is Euclid Number or not
- Check whether a number is Non-hypotenuse 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.