Number of Well Performing Groups
Updated
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 serverint 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
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, wherenis the length ofload1 <= load[i] <= 10^90 <= 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