Minimum Chunks Required (Akuna Shang Hai)
Reported by candidates from Akuna's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Akuna hit candidates with this one in February, and it's a sorting problem disguised as an optimization puzzle. You're given an array and need to find the minimum number of chunks you can split it into such that sorting each chunk independently gives you the fully sorted array. The trick: a chunk can end at position i if the max element up to i equals i (in a 0-indexed, permutation context). StealthCoder will have your back if the logic slips during the live OA, but understanding the pattern now saves you mental CPU.
Pattern and pitfall
The core insight is that you can safely 'cut' after index i if max(arr[0..i]) equals i. This works because if the maximum value in the first chunk is exactly where it should be in a fully sorted array, nothing in that chunk needs to move past that boundary. Scan left to right, tracking the running maximum, and increment your chunk count each time max equals current index. The greedy approach works: you want chunks as early as possible without violating the sorting invariant. Most candidates miss this and try to overthink with dynamic programming or complex comparisons. The one-pass greedy solution is all you need.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Minimum Chunks Required (Akuna Shang Hai) 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Akuna's OA.
Akuna reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum Chunks Required (Akuna Shang Hai) FAQ
Is this actually a sorting problem or a greedy problem?+
It's greedy first, sorting as context. You're greedily cutting as soon as it's safe (when max equals index), not trying every possible split. The sorting property is just the constraint that validates when a cut is valid.
What if the array isn't a permutation of 0 to n-1?+
If it's a general array, you need to normalize it first. Map each unique value to its rank (0 to n-1), then apply the max-equals-index rule. Check the exact problem wording, but assume you may need this step.
How do I verify my answer is correct?+
Walk through your chunks and check: sort each chunk in place, then check if the result equals the fully sorted array. If yes, your chunk count is right. This sanity check takes seconds and catches off-by-one errors.
Can this be solved in one pass?+
Yes. Track max as you iterate. When max equals your current index, you can end a chunk there. Increment your chunk counter. Continue. One loop, O(n) time, O(1) space. That's the whole solution.
What's the most common mistake on this one?+
Overthinking. Candidates try to dynamically program or segment, when they should just ask: can I cut here safely. The max-equals-index check is the only rule you need. Miss that, and you'll write bloated code that times out or fails edge cases.