Menu

Earn Premium with Referrals

Invite your friends and earn Premium rewards through our referral program.

See how it works and start inviting friends.

Hourglass Puzzle
INTERVIEWPUZZLE

Hourglass Puzzle

Learn how to measure a precise time interval using hourglasses with different durations and carefully timed flips.

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”.

  1. Start both hourglasses at the same time.
  2. When the 4-min runs out, flip it immediately. (Remaining: 4-min has 4, 7-min has 3).
  3. When the 7-min runs out (at total time = 7), the 4-min has 1 minute left.
  4. Start the 9-minute timer now.
  5. Let the remaining 1 minute in the 4-min hourglass run out. (Time passed: 1).
  6. Flip the 4-min hourglass twice. (Time passed: 1+4+4={9}1 + 4 + 4 = \mathbf\{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=97x + 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=0T=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.

My Private Notes

Notes are auto-saved locally to this device.