Group Students (AS Intern, it may apply to other interns) π
Updated
Problem statement
Amazon Technical Academy (ATA) provides in-demand, technical training to current Amazon employees looking to broaden their skill sets. ATA has admitted a group of n prospective trainees with varying skill levels. To better accommodate the trainees, ATA has decided to create classes tailored to the skill levels. A placement examination will return a skill level that will be used to group the trainees into classes, where levels[i] represents the skill level of trainee i. All trainees within a class must have a skill level within maxSpread, a specified range of one another. Determine the minimum number of classes that must be formed.
Function
groupStudents(levels: int[], maxSpread: int) β int
Complete the function groupStudents in the editor.
groupStudents has the following parameter(s):
int levels[n]: the skill level for each studentint maxSpread: the maximum allowed skill level difference between any two members of a class
Returns
int: the minimum number of classes that can be formed
Examples
Example 1
levels = [1, 4, 7, 3, 4]maxSpread = 2return = 3
The trainees in any class must be within maxSpread = 2 levels of each other. In this case, one optimal grouping is (1, 3), (4, 4), and (7). Another possible grouping is (1), (3, 4, 4), (7). There is no way to form fewer than 3 classes.
Example 2
levels = [4,8,1,7]maxSpread = 3return = 2Group students with levels 1 and 4 together, and levels 7 and 8 together. Each group has a spread at most 3. One group cannot contain both 1 and 8, so two groups are necessary.
Example 3
levels = [4,1,2,5,3]maxSpread = 0return = 5With a spread of 0, every group must have one skill value. All five levels are different, so five groups are required.
Constraints
1 <= levels.length <= 1000001 <= levels[i] <= 10000000000 <= maxSpread <= 1000000000
More Amazon interview questions
- Lexicographically Largest IdentifierOA Β· Seen Nov 2026
- Assign Escalations to TeamsONSITE INTERVIEW Β· Seen Nov 2026
- Best Time to Buy and Sell StockONSITE INTERVIEW Β· Seen Nov 2026
- Course SchedulePHONE SCREEN Β· ONSITE INTERVIEW Β· Seen Nov 2026
- Maximize Shipment Order by Sorting One WindowOA Β· Seen Nov 2026
- Maximum Earnings Across WarehousesONSITE INTERVIEW Β· Seen Nov 2026
- Priority Message BufferONSITE INTERVIEW Β· Seen Nov 2026
- Search in a Rotated Sorted ArrayPHONE SCREEN Β· ONSITE INTERVIEW Β· Seen Nov 2026
- Top K Frequent ElementsOA Β· PHONE SCREEN Β· ONSITE INTERVIEW Β· Seen Nov 2026
- Fill One Exact-Length Binary WindowOA Β· Seen Nov 2026
Similar questions at other companies
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) Β· OASusquehanna International Group (SIG) interview questions
- Maximum Apples That Fit in a BoxVirtu Financial Β· OAVirtu Financial interview questions
- Server ManagementRippling Β· OARippling interview questions
- Maximum Three-Server Difficulty ScoreVisa Β· OAVisa interview questions
- Economical TripAccenture Β· OAAccenture interview questions
- Minimum Pile Reduction StepsAmerican Express Β· OAAmerican Express interview questions
- Maximum Production Within PowerZomato / Eternal Β· OAZomato / Eternal interview questions
- Can Every Package Fit in a BoxIMC Trading Β· OAIMC Trading interview questions
- Compute Walking DistanceTikTok Β· OATikTok interview questions
- Minimum Tunnel Crossing TimeArcesium Β· OAArcesium interview questions