FastPrepGet Minimum Operations to Sort Array
Problems/Get Minimum Operations to Sort Array

Get Minimum Operations to Sort Array

Moveworks logoMoveworks● HardFULLTIMEINTERNOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Corrected on 2026-07-19 to use a 64-bit return value, because the total number of split operations can exceed a 32-bit integer under the reported constraints. The judged core task matches the visible source at about 99%.

You are given an unsorted positive-integer array arr of length n. You may perform the following operation any number of times:

  • Select an element arr[i] and replace it with two positive integers a and b such that a + b = arr[i].

Return the minimum number of operations required to make the resulting array non-decreasing.

Function

getMinimumOperationsToSortArray(arr: int[], n: int) → long

Examples

Example 1

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

Split 4 into 2, 2, producing [3, 2, 2, 3]. Then split 3 into 1, 2, producing the non-decreasing array [1, 2, 2, 2, 3]. This uses two operations.

Constraints

  • 1 <= n <= 10^5
  • 1 <= arr[i] <= 10^9

More Moveworks interview questions

  • Underline Shortest Unique SubstringsPHONE SCREEN · Seen Oct 2026
  • Word BreakONSITE INTERVIEW · Seen Sep 2026
  • Minimum Moves to Sort ArrayOA · Seen Jul 2024
  • Number of Balanced StringsOA · Seen Jul 2024
  • Find Maximum Number of StringsOA · 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 long getMinimumOperationsToSortArray(int[] arr, int n) {
      // write your code here
    }

}
Checking account…