Cracking The Coding Interview/Q 6.3

From Software Engineers Wiki
Jump to: navigation, search

You have a five-quart jug, a three-quart jug, and an unlimited supply of water (but no measuring cups). How would you come up with exactly four quarts of water? Note that the jugs are oddly shaped, such that filling up exactly "half"of the jug would be impossible.


  1. Prepare jug A : 5 quarts, jug B : 3 quarts
  2. Fill A with 5 quarts, then pour it to B. A will have 2 quarts left
  3. Empty B, move water from A to B, fill the jug A up : A has 5 quarts, B has 2 quarts.
  4. move 1 quart of water from A to B : A has 4 quarts, B has 3 quarts.
Personal tools