Created
August 16, 2019 09:54
-
-
Save priyankvex/b10678a1b4fc7a172e709ef1d9821124 to your computer and use it in GitHub Desktop.
Minimum numbers of toggles to turn all the light bulbs on
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution(object): | |
def solve(self, a): | |
is_flip_on = False | |
flips = 0 | |
for n in a: | |
if not is_flip_on and n == 1: | |
continue | |
elif is_flip_on and n == 0: | |
continue | |
elif not is_flip_on and n == 0: | |
flips += 1 | |
is_flip_on = not is_flip_on | |
elif is_flip_on and n == 1: | |
flips += 1 | |
is_flip_on = not is_flip_on | |
return flips | |
if __name__ == "__main__": | |
a = [0, 0, 0, 1] | |
ans = Solution().solve(a) | |
print(ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment