Showing posts with label bulb. Show all posts
Showing posts with label bulb. Show all posts

100 Switches & 100 bulbs

There are 100 switches in a room operating 100 bulbs. At iteration '0' all switches are OFF. For every iteration 'i', all switches that are multiples of 'i' are toggled (turn OFF if ON, turn ON if OFF).

You need to find the state of the 'k'th switch/bulb (1<=100) after the 'i' th iteration

Expected O(1) time and space complexity.
 
Moviehole-madhurtanwani © 2010 | Designed by Chica Blogger | Back to top