We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The trick here is that for every bulb, its switch will toggle 1 + (2k) bulbs, that is, the one bulb where you toggled the switch, plus k other bulbs each side. Unfortunately, that leaves me flummoxed for cases where the number n is not a multiple of 1 + 2k.
Consider the same parameters as the example, but with four bulbs. You turn off the second bulb, and bulbs 1 to 3 turn off. Bulb 4 is still on. But then you turn off bulb 4, and bulbs 2 and 3 come back on. You can try turning off bulb 2, but then bulb 1 comes back on, or bulb 3, but then bulb 4 comes back on. I'm not seeing any way to do it without either one or two bulbs always being on.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Turn Off the Lights
You are viewing a single comment's thread. Return to all comments →
The trick here is that for every bulb, its switch will toggle 1 + (2k) bulbs, that is, the one bulb where you toggled the switch, plus k other bulbs each side. Unfortunately, that leaves me flummoxed for cases where the number n is not a multiple of 1 + 2k.
Consider the same parameters as the example, but with four bulbs. You turn off the second bulb, and bulbs 1 to 3 turn off. Bulb 4 is still on. But then you turn off bulb 4, and bulbs 2 and 3 come back on. You can try turning off bulb 2, but then bulb 1 comes back on, or bulb 3, but then bulb 4 comes back on. I'm not seeing any way to do it without either one or two bulbs always being on.