Back to problems

Minimum Steps to Achieve Target State

Algorithm · Cisco · Medium

Problem You are given four jugs, [J1, J2, J3, J4], with capacities [C1, C2, C3, C4]. Their starting water amounts are [S1, S2, S3, S4], and the required ending amounts are [F1, F2, F3, F4]. Find the minimum number of steps needed to transform the initial configuration into the final configuration. In one step, water may be transferred between two jugs, and no water may be discarded during the process. Return -1 when the requested final configuration cannot be reached. Input…

Checking your access…