Bulb Switcher

Medium · Math & Number Theory · about 10 minutes

Asked at LinkedIn, Google, Amazon, Microsoft.

n bulbs start off. In round 1 you turn every bulb on; in round 2 you toggle every 2nd bulb; in round i you toggle every i-th bulb; up to round n. Return how many bulbs are on at the end.