I had an infinite supply of water and a 5 liters and 3 liters jars.
How would you measure exactly 4 liters in least number of steps ?
1. Fill 5 litre jar ( 5j - 5, 3j - 0)
2. Transfer to 3 litre jar (5j - 2, 3j - 3)
3. Empty 3 litre jar ( 5j - 2, 3j - 0)
4. Transfer 2 litre from 5 litre jar to 3 litre jar (5j - 0, 3j - 2)
5. Fill 5 litre jar(5j - 5, 3j - 2)
6. Transfer 1 litre from 5 litre jar to 3 litre jars(5j - 4, 3j - 3)