FastPrepMinimum Moves to Sort Array
Problems/Minimum Moves to Sort Array

Minimum Moves to Sort Array

Moveworks logoMoveworks● HardFULLTIMEINTERNOA

Updated Sep 2026

QuestionFunctionExamples

Problem statement

Given an array arr[] of N integers, the task is to find the minimum number of moves to sort the array in non-decreasing order by splitting any array element into two parts such that the sum of the parts is the same as that element.

Function

minimumMovesToSortArray(arr: int[]) → int

Examples

Example 1

arr = [3, 4, 2]return = 2

The moves are:

  1. Split 4 into two parts (2, 2). Array becomes arr[] = {3, 2, 2, 2}
  2. Split 3 into two parts (1, 2). Array becomes arr[] = {1, 2, 2, 2, 2}

Example 2

arr = [3, 2, 4]return = 1

Split 3 into two parts (1, 2). Array becomes (1, 2, 2, 4).

Example 3

arr = [5, 6, 5, 7, 9]return = 2

At Index = 0, 5 breaks into 2, 3 so array becomes (2, 3, 6, 5, 7, 9). At Index = 1, 6 breaks into 3, 3 so array becomes (2, 3, 3, 3, 5, 7, 9). Now the array is sorted (2, 3, 3, 3, 5, 7, 9), so the count is 2. Hence the function returns 2.

More Moveworks interview questions

  • Underline Shortest Unique SubstringsPHONE SCREEN · Seen Oct 2026
  • Word BreakONSITE INTERVIEW · Seen Sep 2026
  • Number of Balanced StringsOA · Seen Jul 2024
  • Find Maximum Number of StringsOA · Seen Jul 2024
  • Get Minimum Operations to Sort ArrayOA · Seen Jul 2024

Similar questions at other companies

  • Hard Disk Clustering CostConfluent · OAConfluent interview questions
  • Minimum BeautyBloomberg LP · OABloomberg LP interview questions
  • Minimum Operations to Make a SubsequenceGoogle · OAGoogle interview questions
  • Maximize K-Element AND with an Increment BudgetAmazon · OA
  • Split Array to Minimize the Largest SumInfosys · OAInfosys interview questions
  • Split Array Largest SumAuxoAI · OA
  • Delete and Freeze GameRubrik · OARubrik interview questions
  • Lock CodeVisa · OAVisa interview questions
  • Starlink Beam PlannerSpaceX · OA · PHONE SCREENSpaceX interview questions
  • Most Segments That Sort the ArrayRippling · OARippling interview questions
All Moveworks interview questionsSee Moveworks hiring insights
Saved
class Solution {
    public int minimumMovesToSortArray(int[] arr) {
      // write your code here
    }

}
Checking account…