Google Interview: There are 2 bottles of 5 liters and 3 liters. Measure out 4 liters

The answer is fill bottle 3 and pour it into 5, then pour it all the way to the top, then pot 3 has 1 liter left. Pour out all the water in pot 5, then pour in 1 liter from pot 3, then fill pot 3 and pour in, it’s 4