FastPrepMinimum Steps to Achieve Target State
Problems/Minimum Steps to Achieve Target State

Minimum Steps to Achieve Target State

Cisco logoCisco● HardFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You have 4 jugs, J1 to J4. Jug i can hold at most capacities[i] units of water and starts with initial[i] units.

In one step, you choose two different jugs and pour water from the first into the second. You keep pouring until the first jug is empty or the second jug is full, whichever happens first. No water is ever added or lost.

Return the minimum number of steps needed to make the jugs hold exactly target[i] units each. If the start already matches the target, return 0. If the target cannot be reached, return -1.

Function

minStepsToAchieveTargetState(capacities: int[], initial: int[], target: int[]) → int

Examples

Example 1

capacities = [12, 13, 12, 10]initial = [6, 6, 0, 0]target = [12, 0, 0, 0]return = 1

J1 holds 6 units and has room for 6 more. Pour J2 (6 units) into J1: all 6 units move, J2 becomes empty, and the jugs hold [12, 0, 0, 0]. That is the target, reached in one step.

Constraints

  • capacities.length == initial.length == target.length == 4
  • 1 ≤ capacities[i] ≤ 500
  • 0 ≤ initial[i], target[i] ≤ capacities[i]
  • initial[0] + initial[1] + initial[2] + initial[3] == target[0] + target[1] + target[2] + target[3]

More Cisco interview questions

  • Check if a String Is a PalindromePHONE SCREEN · Seen Nov 2026
  • Find Unique ElementsPHONE SCREEN · Seen Nov 2026
  • First Letter to Appear TwicePHONE SCREEN · Seen Nov 2026
  • Middle of a Linked ListPHONE SCREEN · Seen Nov 2026
  • Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
  • Reverse a StringPHONE SCREEN · Seen Nov 2026
  • Valid ParenthesesPHONE SCREEN · Seen Nov 2026
  • K-Step Bit Flip with RetentionPHONE SCREEN · Seen Nov 2026
  • Todo Task Manager OperationsONSITE INTERVIEW · Seen Oct 2026
  • Find the Duplicate Number Without Modifying the ArrayONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Lowest Common Ancestor with a Changing RootInfosys · OAInfosys interview questions
  • Minimum Tree Diameter After Removing K LeavesMathWorks · OAMathWorks interview questions
  • Minimum Numeric Code TransformationAdobe · OAAdobe interview questions
  • Special Diameter EndpointsAgoda · OAAgoda interview questions
  • Satellite Network Message PropagationOptiver · OAOptiver interview questions
  • Thread Count (Also for Infra Automation Intern)Snowflake · OASnowflake interview questions
  • Avoiding the Obstacles (IMC Sydney 🦪)IMC Trading · OAIMC Trading interview questions
  • Office to Home WalkNutanix · OANutanix interview questions
  • Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions
  • Delivery Management SystemAkuna Capital · OAAkuna Capital interview questions
All Cisco interview questionsSee Cisco hiring insights
Saved
class Solution {
    public int minStepsToAchieveTargetState(int[] capacities, int[] initial, int[] target) {
      // write your code here
    }

}
Checking account…