Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • OOP & Testbench Puzzles25
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
    • Classic Brain Teasers
      • 9 Balls, 1 Heavier, 2 Weighings
      • 2 Eggs and 100 Floors
      • Burning Ropes to Measure 45 Minutes
      • Measure 4 Liters with 3L and 5L Jugs
      • Bridge and Torch (1, 2, 7, 10 Minutes)
      • 100 Prisoners and One Light Switch
    • Probability Puzzles
    • Digital Logic Puzzles
    • Debugging Riddles
    • Logic & Aptitude Puzzles: Tricky Q&A
  • Scenario & Debug Puzzles25
  • Interview Prep: Puzzle Rounds5
  • DV Puzzle Cheatsheet
Loading lesson

‹Classic Brain Teasers
  1. Topics
  2. DV Interview Puzzles
  3. Logic & Aptitude Puzzles
  4. Classic Brain Teasers
  5. 100 Prisoners and One Light Switch

VLSI DV Interview Puzzles · All levels

100 Prisoners and One Light Switch

100 prisoners are isolated. A guard picks one random prisoner daily to visit a room with one light switch (initially OFF). Prisoners may agree on a strategy once beforehand. They can declare when everyone has visited the room at least once. How?

On this page

    Puzzle

    Difficulty: Hard · Puzzle 6 of 6 · Topic: Classic Brain Teasers

    100 prisoners are isolated. A guard picks one random prisoner daily to visit a room with one light switch (initially OFF). Prisoners may agree on a strategy once beforehand. They can declare when everyone has visited the room at least once. How?

    Hint

    Use one designated counter and one-time signals from others.

    Step-by-step solution

    Diagram
    1) Designate prisoner P0 as counter.
    2) Every non-counter prisoner toggles OFF->ON exactly once in their lifetime, only when they first enter and see OFF.
    3) P0 rule: whenever P0 enters and sees ON, set it to OFF and increment count.
    4) Each increment corresponds to one unique non-counter prisoner having signaled.
    5) When P0 reaches count = 99, P0 can safely declare all 100 have visited.
    6) Correctness: no non-counter contributes more than once; every non-counter eventually visits and can contribute under random fair selection.

    Answer

    Answer: Use one counter prisoner counting 99 unique ON signals from the other prisoners.

    Why candidates get it wrong

    Allowing non-counters to toggle multiple times causes overcount and false declaration.

    Interviewer follow-up

    How would strategy change if initial switch state were unknown?

    Related topics

    • Back to Classic Brain Teasers

    • Logic & Aptitude Puzzles section

    Previous

    160 / 210

    Next: Probability Puzzles

    Up next

    Up nextProbability Puzzles

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • 9 Balls, 1 Heavier, 2 Weighings
    • 2 Eggs and 100 Floors
    • Burning Ropes to Measure 45 Minutes