Cisco OA-4 2022
Problem Description
You have four jugs, labeled [J1, J2, J3, J4], with capacities [C1, C2, C3, C4] and initial water amounts of [S1, S2, S3, S4]. The objective is to determine how many steps are required to reach the final state of [F1, F2, F3, F4] by transferring water between the jugs without any loss.
Constraints:
- 0 < C[i] <= 500 for each i: [1, 4]
- 0 <= S[i], F[i] <= C[i] for each i: [1, 4]
- Sum(S[i]) = Sum(F[i])
Input:
- The first line specifies the number of entries in the array, which is 12 in our case.
- The next 4 lines contain the capacities of the 4 jugs.
- The next 4 lines contain the initial content of the 4 jugs.
- The next 4 lines contain the final content of the 4 jugs.
Output:
The minimum number of steps required to reach the final state (F) from the initial state (S). Return -1
if it's not possible.
Examples:
12
13
12
10
5
6
6
0
0
12
0
0
0
Output: 1
Explanation: Step 1: Pour 6 Litres of water from Jug 2 to Jug 1.