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.
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 number can be displayed using seven segment led
- Minimum digits to be removed to make either all digits or alternating digits same
- Distinct strings with odd and even changes allowed
- Maximum length substring having all same characters after k changes
- Make a lexicographically smallest palindrome with minimal changes
- Minimum changes to a string to make all substrings distinct
- Minimum bit changes in Binary Circular array to reach a index
- Check if a String can be converted to Pangram in K changes
- Minimum changes required to make first string substring of second string
- Number of ways to swap two bit of s1 so that bitwise OR of s1 and s2 changes
- Minimum changes required such that the string satisfies the given condition
- Minimum flips required to form given binary string where every flip changes all bits to its right as well
- Count of binary strings of length N having equal count of 0's and 1's and count of 1's ≥ count of 0's in each prefix substring
- Count of strings that become equal to one of the two strings after one removal
- Count of N size strings consisting of at least one vowel and one consonant
- Maximize the value of A by replacing some of its digits with digits of B
- 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
- Number formed by deleting digits such that sum of the digits becomes even and the number odd
- Python | Display images with PyGame
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.