Suppose we have a number n, and we have another input c. We have to check whether n can be displayed using 7-segment displays or not. Now here is a constraint. We are only allowed to glow at most c number of LEDs.
So, if the input is like n = 315 c = 17, then the output will be True as 315 needs 12 LEDs and we have 17.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
seg = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] def solve(n, c) : s = str(n) led_count = 0 for i in range(len(s)) : led_count += seg[ord(s[i]) - 48] if led_count <= c: return True return False n = 315 c = 17 print(solve(n, c))