Opening your workspace…
Workspace/Coding room
Opening your workspace…
At the firefly hotel every window has a bedside switch. Pressing it flips its own light and the lights directly above, below, left and right, wherever those windows exist. The porter wants every room dark. Given the lit (1) and dark (0) windows, return the fewest presses he needs, or -1 if the guests must sleep with the lights on. Practice rank · 2 kyu (Brewery estimate).
["010","111","010"]OUTPUT1Pressing the middle switch extinguishes all five lights.
["10"]OUTPUT-1Either switch flips both rooms. Exactly one guest always has a light.
Choose presses for the first floor. After that, a light still burning upstairs forces the switch directly below it.
function solve(windows) { // Write your answer here. }
Tab inserts two spaces. Shift+Tab outdents. Use the arrow keys and Tab to choose a suggestion. Press Escape, then Tab, to leave the editor. Press Control or Command with apostrophe to run samples or with Enter to submit.
["010","111","010"]1