Fewest Student Groups Within a Level Gap
Updated
Problem statement
Students must be split into groups. levels[i] is the level of student i. Inside every group, any two students' levels may differ by at most maxGap.
Every student goes into exactly one group, and a group can have any number of students. Return the smallest number of groups needed.
Function
fewestGroups(levels: int[], maxGap: int) → intExamples
Example 1
levels = [10,3,6,12,20]maxGap = 4return = 3Sorted, the levels are 3, 6, 10, 12, 20. Put 3 and 6 together (difference 3), then 10 and 12 (difference 2), and 20 alone.
Two groups are not enough: 3 and 20 must be in different groups, and 10 is more than 4 away from both 3 and 20, so it would need a third group anyway. The answer is 3.
Example 2
levels = [5,5,5,5]maxGap = 0return = 1All levels are equal, so every difference is 0. One group holds everyone.
Example 3
levels = [1,100]maxGap = 99return = 1The difference is exactly 99, which is allowed (at most maxGap). One group.
Constraints
1 <= levels.length <= 10001 <= levels[i] <= 10^90 <= maxGap <= 10^9
More DocuSign Online Assessment questions
- Max Sum With No Two Adjacent PicksOA · Seen Apr 2026
- Max Sum With No Two Adjacent Picks on a CircleOA · Seen Apr 2026
- Beautiful Number OrderingsOA · Seen Feb 2026
- Grid Path With the Most ClearanceOA · Seen May 2025
- Vehicle Mixes for a Wheel TotalOA · Seen May 2025
- Count Sales Rung Up at the Wrong PriceOA · Seen Feb 2021
- Most Disjoint Intervals From Starts and DurationsOA · Seen Feb 2021
- Fewest Fountains to Water the GardenOA · Seen Feb 2021
- Lowest Start That Keeps Running Totals PositiveOA · Seen Feb 2021
- Alphabetize a Word ListOA · Seen May 2020
Similar questions at other companies
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
- Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
- Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
- Maximize Minimum Deployment DifficultyJP Morgan Chase · OAJP Morgan Chase interview questions
- Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
- Maximize Center A Package BenefitAmazon · OA
- EV Charging Cost OptimizationTata Consultancy Services · OATata Consultancy Services interview questions
- Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions