FastPrepGroup Students (AS Intern, it may apply to other interns) πŸ‘
Problems/Group Students (AS Intern, it may apply to other interns) πŸ‘

Group Students (AS Intern, it may apply to other interns) πŸ‘

Amazon logoAmazon● EasyINTERNNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: About 98% source match. The source gives the grouping rule, bounds and examples. The practice version returns the minimum number of groups through the same callable.

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):

  1. int levels[n]: the skill level for each student
  2. int 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 = 2

Group 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 = 5

With 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 <= 100000
  • 1 <= levels[i] <= 1000000000
  • 0 <= 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

Interview reports that mention this question

  • Amazon Intern OA Problems: Every Task We Have (Part 2 of 5)

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
See Amazon hiring insights
Saved
class Solution {
    public int groupStudents(int[] levels, int maxSpread) {
        // write your code here
    }

}
Checking account…