Reported July 2026
DRWbinary search

Minimize Maximum Group Difference

Reported by candidates from DRW's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live DRW OA. Under 2s to a working solution.
Founder's read

DRW reported this one in July 2026, and the trap is hiding in plain sight: it looks like a partition problem, but the edge case is what sinks the naive attempt. Splitting into three non-empty groups with small arrays, duplicates, or exactly three elements breaks the loose solutions. If your OA invite is for DRW, expect this shape. The real pattern is sort plus binary search on the answer, with a greedy check. Hash tables are a red herring. StealthCoder sits invisibly as a safety net if you blank on the feasibility check mid-assessment, but the idea is short enough to own tonight.

The problem

You are given an array A consisting of N integers. Divide all elements into three non-empty groups. Each element must belong to exactly one group.
For each group, define its difference as the largest integer in the group minus the smallest integer in the group.
Your goal is to make the maximum of these three group differences as small as possible.
Return the minimum possible value of that maximum difference.

Function
solution(A: int[]) → int

Examples
Example 1
A = [11,5,3,12,6,8,1,7,4]
return = 3
One optimal division is [3,1,4], [5,6,8,7], and [11,12]. Their differences are 3, 3, and 1, so the maximum difference is 3.
Example 2
A = [10,14,12,1000,11,15,13,1]
return = 5
One optimal division is [1], [10,14,12,11,15,13], and [1000]. The maximum group difference is 5.
Example 3
A = [4,5,7,10,10,12,12,12]
return = 2
One optimal division is [4], [5,7], and [10,10,12,12,12]. The group differences are 0, 2, and 2.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Sort the array first. Groups only need to be contiguous ranges in sorted order, because mixing non-adjacent values never helps. Then binary search on the answer D from 0 to max minus min. For a given D, greedily start a group at the smallest uncovered element and swallow everything within D of it. Count the groups. If you need three or fewer, D is feasible. Here's the pitfall: feasible with fewer than three groups still counts, but you must have three non-empty groups, so if N is at least 3 you can always split a larger group to make more without raising the max. Check N equal to 3 (answer 0) and heavy duplicates. Example 2 shows the outlier 1000 and 1 each taking their own group. If the greedy count logic slips during the live OA, StealthCoder can give you the working code as a hedge. Complexity is O(N log N + N log range).

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Minimize Maximum Group Difference 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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass DRW's OA.

DRW reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimize Maximum Group Difference FAQ

What's the trick for DRW's Minimize Maximum Group Difference?+

Sort, then binary search the answer. For a candidate difference D, greedily cover the sorted array with groups where each spans at most D. If you need at most three groups, D works. The smallest feasible D is your result.

Why is hash-table the hinted pattern if it isn't one?+

Tags on reported OAs are noisy. Nothing here needs a hash map. Duplicates just sit next to each other after sorting. Trust sort plus binary search, and don't waste time building a frequency map.

What edge cases break a naive solution?+

Exactly three elements (answer is 0), all equal values, and big outliers like the 1000 in Example 2. Also remember groups must be non-empty, so if greedy uses fewer than three groups, you can still split to reach three without increasing the max.

Is there a non-binary-search approach?+

Yes. After sorting, pick two cut points among N-1 gaps and take the max of the three range widths. That's O(N^2) brute force, fine for small N but risky on large inputs. A smarter version cuts at the two largest gaps, but verify against the examples before trusting it.

How do I prepare for this in 48 hours?+

Write the binary-search-on-answer template once from scratch, then run Examples 1 to 3 by hand. Test N equal to 3 and an all-duplicates array. Practice explaining why contiguous sorted groups are optimal. That covers this pattern and its close variants.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with DRW.

OA at DRW?
Invisible during screen share
Get it