Given a number n. Count the number of changes in LED light when display one after another of a given number. (Initially all LED is off). Number is given input in the form of a string.
See this image of seven segment display for better understanding.
Input : n = "082" Output : 9 We need 6 LED lights to display 0 in seven segment display. We need 7 lights for 8 and 5 lights for 2. So total on/off is 6 + 1 + 2 = 9. Input : n = "12345" Output : 7
Source :Morgan Stanley Interview Set 20
The idea is to pre-compute the led lights required to display a given number. Now iterate the number and keep adding the changes. For the implementation, a basic concept of string hashing is used.
Below is the implementation of above problem.
- Count of Numbers in Range where the number does not contain more than K non zero digits
- Count numbers in range such that digits in it and it's product with q are unequal
- Program to count vowels, consonant, digits and special characters in string.
- Python | Display images with PyGame
- Python | Display text to PyGame window
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Maximize the given number by replacing a segment of digits with the alternate digits given
- Maximize the value of A by replacing some of its digits with digits of B
- Count numbers < = N whose difference with the count of primes upto them is > = K
- Smallest odd digits number not less than N
- Pairs whose concatenation contain all digits
- Check if a number has digits in the given Order
- Number of even substrings in a string of digits
- Smallest number with sum of digits as N and divisible by 10^N
- Print all possible words from phone digits
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.