Min Operations to Sort Array
Reported by candidates from Moveworks's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Moveworks asked this in July 2024, and it's a sorting disguise question. You get an array and need to find the minimum number of operations to make it sorted. The trick isn't brute force enumeration of swaps. It's recognizing that you're really asking: how many moves do I need if each move lets me rearrange a specific subset of elements. The operation itself is the key. Most candidates miss that the operation type (swap two elements, rotate a segment, increment by 1) defines the entire solution path. StealthCoder can catch the operation definition if you blank on the rules mid-problem.
Pattern and pitfall
This problem lives in the sorting and greedy families. The core insight: once you know what one operation does, you count how many times you need it or how many elements fall outside the 'already sorted' subsequence. A common trap is solving 'minimum swaps to sort' when the operation is actually 'pick an index and multiply by 2' or 'reverse a subarray.' Read the operation definition twice. Then ask: can I greedily apply it (always move the worst-placed element first), or do I need dynamic programming to find the optimal sequence. Most Moveworks versions test whether you recognize that certain subsequences don't need operations at all. That's where longest increasing subsequence patterns hide. StealthCoder helps you recognize the operation in real time if the problem statement is dense.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Min Operations to Sort Array cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as longest increasing subsequence. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Moveworks's OA.
Moveworks reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Min Operations to Sort Array FAQ
What's the operation, and how much does it matter?+
Everything. The operation type (swap, rotate, multiply, add) determines if this is greedy, graph-based, or DP. Moveworks hides it in the middle of the problem. Read the operation twice. Write pseudocode for one operation before coding the solution.
Is this a LIS (longest increasing subsequence) problem in disguise?+
Possibly. If the operation is 'pick one element and move it anywhere,' then elements already in sorted order don't need operations. Count array length minus LIS length. But first confirm the operation allows free placement.
Can I solve this greedily?+
Only if every operation is independent and commutative (order doesn't matter). If two operations interfere, you need DP or BFS. Test on a small array: does operation order change the answer?
How do I prepare in 48 hours if I've never seen this exact problem?+
Review LeetCode 1109, 912, and 315. Understand swap-based sorting, segment reversals, and longest increasing subsequence. Know BFS on state space. Moveworks likes pattern recognition over grinding.
What if I blank on the operation in the real OA?+
Write out the exact operation rules in pseudocode before coding. Trace one example by hand. If you're stuck, a tool like StealthCoder can re-read the problem and suggest the pattern while you code.