Google Interview Question: Given two buckets which you k... | Glassdoor

## Interview Question

Operations Engineer Interview Moncks Corner, SC

# Given two buckets which you know to hold three gallons and

five gallons, which have no graduations or other markings that would let you easily measure amounts less than 3 or 5 gallons of water, how would you measure exactly four gallons of water?

2

There are two ways to do that, each has its Pros and Cons

Let's define the buckets first..

3-Gallon bucket = A
5-Gallon bucket = B

FIRST WAY: MORE STEPS and LESS WATER LOSS

Step ..............(A,B)

Fill A ............. (3,0)
Move A to B ............. (0,3)
Fill A ............. (3,3)
Move A to B ............. (1,5)
Empty B .............. (1,0)
Move A to B ............. (0,1)
Fill A ............. (3,1)
Move A to B ............. (0,4)

No. of steps is 8, Total Loss of water is 5 Gallons

SECOND WAY: Less STEPS and MORE WATER LOSS

Step ..............(A,B)
Fill B ..............(0,5)
Move B to A ..............(3,2)
Empty A ..............(0,2)
Move B to A ..............(2,0)
Fill B ..............(2,5)
Move B to A ..............(3,4)

No. of steps is 6, Total Loss of water is 6 Gallons

Toufik Kannab on Jul 21, 2013
0

3,0
0,3
3,3
1,5
0,5
3,2
2,5
3,4

Rahul on Mar 13, 2016