Minimize Maximum Group Difference
Updated
Problem statement
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[]) → intExamples
Example 1
A = [11,5,3,12,6,8,1,7,4]return = 3One 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 = 5One 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 = 2One optimal division is [4], [5,7], and [10,10,12,12,12]. The group differences are 0, 2, and 2.
More DRW Online Assessment questions
- Count Balanced Nodes in a Rooted TreeOA · Seen Sep 2026
- Largest Number With Even Digit FrequenciesOA · Seen Sep 2026
- Shortest Path Around Rectangular ObstaclesOA · Seen Sep 2026
- 2020 Account Balance with Monthly Card FeesOA · Seen Aug 2026
- Nested In-Memory Database TransactionsOA · Seen Aug 2026
- Password Requirement CheckOA · Seen Aug 2026
- Remove Excess Consecutive CharactersOA · Seen Aug 2026
- Last Round for Each PlayerOA · Seen Jul 2026
- Shortest Compressed Length After RemovalOA · Seen Jul 2026
- Doctor Appointment Slot AssignmentOA · Seen Jul 2026
Similar questions at other companies
- Minimum-Cost Solar Rooftop AllocationDeloitte · OADeloitte interview questions
- Maximize Number of Produced CarsMicrosoft · OAMicrosoft interview questions
- Aggressive CowsPeopleStrong · OAPeopleStrong interview questions
- Spread Cows Across StallsExpedia · OAExpedia interview questions
- Aggressive CowsAmazon · PHONE SCREEN
- Maximize the Minimum Cone DistanceSumo Logic · PHONE SCREEN
- Maximize Fish over Limited HoursByteDance · PHONE SCREENByteDance interview questions
- Count Lamps Lighting Each PointAirbnb · OAAirbnb interview questions
- Find Minimum TimeAlphaSense · OA
- Find Minimum TimeBlackRock · OABlackRock interview questions