Minimum Steps to Achieve Target State

Problem Overview

  • Determine the minimum steps to reach a target water distribution across 4 jugs by transferring water without loss.
  • Input: count line then 12 values—4 capacities, 4 initial amounts, 4 final amounts; Output: minimum steps or -1 if impossible.
  • Constraints: 0 < Ci ≤ 500; 0 < Si, Fi ≤ Ci; Sum(Si) = Sum(Fi).
  • Classic water jug domain for state-transition reasoning.
  • Asked in Cisco interviews; a common coding interview problem and interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: