FastPrepFewest Student Groups Within a Level Gap
Problems/Fewest Student Groups Within a Level Gap

Fewest Student Groups Within a Level Gap

DocuSign logoDocuSign● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A report from November 2020 described this online assessment question. Put students into the fewest groups so that no two levels in a group differ by more than a given gap. The report gave one example input but no answer and no limits.

Here there are 1 to 1000 students with levels from 1 to 10^9, and the gap is 0 to 10^9. We wrote the examples.

Our version is about 90% the same as the reported question.

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) → int

Examples

Example 1

levels = [10,3,6,12,20]maxGap = 4return = 3

Sorted, 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 = 1

All levels are equal, so every difference is 0. One group holds everyone.

Example 3

levels = [1,100]maxGap = 99return = 1

The difference is exactly 99, which is allowed (at most maxGap). One group.

Constraints

  • 1 <= levels.length <= 1000
  • 1 <= levels[i] <= 10^9
  • 0 <= 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

Interview reports that mention this question

  • DocuSign SWE Intern OA Questions: 53 Experiences (Part 1 of 2)

DocuSign interview experiences

  • DocuSign SWE Intern Interviews: 27 Experiences (Part 2 of 2)
All DocuSign interview questionsSee DocuSign hiring insights
Saved
class Solution {
    public int fewestGroups(int[] levels, int maxGap) {
        // Write your code here.
    }
}
Checking account…