The Puzzle: You have two hourglasses:
- One measures 4 minutes.
- One measures 7 minutes. How can you measure exactly 9 minutes?
1. The Strategy
We need to use the difference between the two to create a “remainder”.
- Start both hourglasses at the same time.
- When the 4-min runs out, flip it immediately. (Remaining: 4-min has 4, 7-min has 3).
- When the 7-min runs out (at total time = 7), the 4-min has 1 minute left.
- Start the 9-minute timer now.
- Let the remaining 1 minute in the 4-min hourglass run out. (Time passed: 1).
- Flip the 4-min hourglass twice. (Time passed: 1+4+4={9}).
2. Alternative Solution (Parallel)
You can also flip the 7-minute hourglass the moment the 4-minute one finishes to create a 3-minute remainder. There are multiple paths, but the logic of “storing” time as a remainder is the same.
Interview-Focused Questions
Q: What is the general rule for hourglasses?
A: Similar to jugs, you are solving 7x+4y=9. However, unlike jugs, you can’t “empty” an hourglass instantly; you have to wait for the sand to flow.
Q: Is there a way to measure 9 mins faster?
A: The method above starts the “9-minute countdown” after an initial 7-minute setup. If you need 9 minutes starting from T=0, you must find a way to make the total elapsed time 9. Some interviewers specify “starting from now” vs “total duration”.
Key Takeaway
Hourglass puzzles test your ability to synchronize asynchronous events.
Premium Content
Unlock Hourglass Puzzle and all premium lessons with a subscription.
From ₹199.99/year — See plans