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

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • Study Route: One Week Before the Interview
  • Study Route: Two Weeks
  • Study Route: Four Weeks (Full Course)4
  • 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
  • UVM Testbench Puzzles25
  • Clock, Reset & CDC Puzzles25
  • Bus and Interface Protocol Puzzles25
  • Interview Prep: Puzzle Rounds7
  • DV Puzzle Cheatsheet
Loading lesson

←Classic Brain Teasers
  1. Topics
  2. DV Interview Puzzles
  3. Logic & Aptitude Puzzles
  4. Classic Brain Teasers
  5. Measure 4 Liters with 3L and 5L Jugs
On this page

    VLSI DV Interview PuzzlesAll levels

    Measure 4 Liters with 3L and 5L Jugs

    You have unmarked 3-liter and 5-liter jugs plus unlimited water. Measure exactly 4 liters.

    Puzzle

    Difficulty: Easy · Puzzle 4 of 6 · Topic: Classic Brain Teasers

    You have unmarked 3-liter and 5-liter jugs plus unlimited water. Measure exactly 4 liters.

    Hint

    Create a 2-liter remainder first, then use it as an offset.

    Step-by-step solution

    Diagram
    1) Fill 5L jug and pour into 3L jug => 5L now has 2L left.
    2) Empty 3L jug.
    3) Pour the 2L from 5L into 3L jug.
    4) Fill 5L jug again.
    5) Pour from 5L into 3L until 3L is full; it needs 1L to go from 2L to 3L.
    6) So 5L jug is left with exactly 4L.

    Answer

    Answer: Sequence leaves 4 liters in the 5L jug after creating 2L in the 3L jug and topping it up.

    How this was checked

    Checked by running a model of the rule in a Python model. A computational check: breadth-first search over all (3 L, 5 L) jug states finds 4 L needs 6 steps, the stated sequence is legal, and the reachable amounts match the gcd rule (3 and 5 reach 0 to 5, 4 and 6 only even amounts).

    Why candidates get it wrong

    Trying to make 4 L in one move. Only differences of the jug sizes (5-3 = 2) are available, so build the 2 L remainder first and then top up the 3 L jug by 1 L.

    Interviewer follow-up

    Can you derive a general solvability rule for jug sizes a and b? Model answer: a target t is reachable iff t <= max(a,b) and t is a multiple of gcd(a,b) (Bezout: you can only change contents by +-a and +-b). For 3 and 5, gcd = 1 so every amount 1 to 5 is reachable; for 4 and 6 only even amounts are.

    Say it out loud

    I can only change the amounts by the jug sizes, so I build up from the difference five minus three, which is two. I fill the five-litre jug and pour into the three, leaving two litres in the five. I empty the three and pour the two litres across, then fill the five again. Now I pour from the five into the three until it is full, and that takes just one litre, since the three already holds two. The five-litre jug is left with exactly four litres; the trap is trying to get four in a single move.

    Related topics

    • Back to Classic Brain Teasers

    • Logic & Aptitude Puzzles section

    Previous

    164 / 293

    Next: Bridge and Torch (1, 2, 7, 10 Minutes)

    Up next

    Up nextBridge and Torch (1, 2, 7, 10 Minutes)

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • 9 Balls, 1 Heavier, 2 Weighings
    • 2 Eggs and 100 Floors
    • 100 Prisoners and One Light Switch