Skip to content

Instantly share code, notes, and snippets.

@priyankvex
Created August 16, 2019 09:54
Show Gist options
  • Save priyankvex/b10678a1b4fc7a172e709ef1d9821124 to your computer and use it in GitHub Desktop.
Save priyankvex/b10678a1b4fc7a172e709ef1d9821124 to your computer and use it in GitHub Desktop.
Minimum numbers of toggles to turn all the light bulbs on
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