Why is the expected output 2 for "5 bulbs"?


  • 0
    E

    From my understanding, the bulbs change as follow:
    1st round: [on,on,on,on,on]
    2nd round: [on,off,on,off,on]
    3rd round: [on,off,off,off,on]
    nth/5th round: [on,off,off,off,off]

    My understanding my be wrong, for it is not clear what should happen between round 4 to round n-1. I simply assumed nothing should happen between those rounds.


  • 1
    L

    round 4 should be [on,off,off,on,on] i.e. only every 4th bulb should be toggled. Here it's only the 4th. if n is bigger, could be 4, 8, 12, ...., 4*I, ....
    so round 5 should be [on,off,off,on,off]. Now only two bulbs are on.


  • 0
    S

    I agree. It didn't mention "and so on" so step 4 is undefined


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.