Ctrl K

Lamps Left Burning

Medium
A hallway has count lamps, numbered 1 to count, all switched off. There are count rounds: in round k every lamp whose number is divisible by k is toggled (a lit lamp goes off, a dark one comes on). So round 1 turns every lamp on, and the last round toggles only lamp count. Return how many lamps are lit after all the rounds.
Example 1
count=5 → 2

After round 1 all five are on. Round 2 turns off 2 and 4, round 3 turns off 3, round 4 turns 4 back on, round 5 turns off 5. Lamps 1 and 4 stay lit.

Example 2
count=0 → 0

There are no lamps, so nothing is lit.

Example 3
count=10 → 3
Constraints
  • 0 ≤ count ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThree Stones Close Ranks MediumLast Viewer in the Right Seat MediumTake From Any Pile MediumA Mirror in Every Base MediumOR of All Subset Sums Medium
loading Python…
Input
count=5
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 88 tests on the server, hidden ones included.