FastPrepNumber of Well Performing Groups
Problems/Number of Well Performing Groups

Number of Well Performing Groups

Amazon logoAmazon● MediumOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Amazon wants to study its network of n servers in different parts of the world. load[i] is the load of server i.

A group of contiguous servers is a run of servers that sit next to each other. It holds every server from one position to another, and no other server.

A group is performing well when its largest load minus its smallest load is exactly k.

Return the number of groups of contiguous servers that are performing well.

For example, let load = [5, 5] and k = 0. The groups are [5], [5] and [5, 5]. Each one has a difference of 0. The answer is 3.

Function

numberOfWellPerformingGroups(load: int[], k: int) → int

Complete the function numberOfWellPerformingGroups in the editor.

numberOfWellPerformingGroups has the following parameters:

  • int load[n]: the load of each server
  • int k: the difference a group needs

Returns int: the number of groups that are performing well

Examples

Example 1

load = [2, 4, 6]k = 2return = 2
Example 1 illustration

The groups are [2], [4], [6], [2, 4], [4, 6] and [2, 4, 6]. Their largest minus smallest loads are 0, 0, 0, 2, 2 and 4. Two groups, [2, 4] and [4, 6], have a difference of exactly 2. The answer is 2.

Constraints

  • 1 <= n <= 5 * 10^4, where n is the length of load
  • 1 <= load[i] <= 10^9
  • 0 <= k <= 10^9

More Amazon interview questions

  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximal SquareONSITE INTERVIEW · Seen Nov 2026
  • Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Diagonal Traversal of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
  • Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
  • Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026

Similar questions at other companies

  • Count Subarrays With Product Equal to KSalesforce · OASalesforce interview questions
  • Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions
  • Reschedule Meetings for Maximum Free TimeFivetran · OAFivetran interview questions
  • Count Subarrays Matching a Comparison PatternCapital One · OACapital One interview questions
  • Count Subarrays with at Least K Equal-Fruit PairsTikTok · OATikTok interview questions
  • Consistent LogsRippling · OARippling interview questions
  • Minimum Team Size From Every StartCognizant · OA
  • Minimum of Fixed-Window MaximaJuspay · OA
  • Sliding-Window Means with IEEE Special ValuesHeadlands Technologies · OAHeadlands Technologies interview questions
  • Maximum Decrypted ScoreMicrosoft · OAMicrosoft interview questions

Interview reports that mention this question

  • Amazon Full-Time OA Problems, Recent Reports (Part 4 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 New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public int numberOfWellPerformingGroups(int[] load, int k) {
      // write your code here
    }

}
Checking account…