FastPrepFastPrep
Problem Brief

Number of Well Performing Groups

OA
See Amazon online assessment and hiring insights

Amazon aims to review its network of m servers deployed across different regions globally. The workloads on these servers are stored in the array workloads. A collection of servers is labeled as performing optimally when the difference between the highest and lowest workloads in that collection equals difference.

A collection is termed a consecutive group if there are two positions x and y such that 1 ≤ x ≤ y ≤ m, where all servers from position x to y are included in the group, with none from outside.

A group of servers is called contiguous servers when there exists x, y such that 1 ≤ x ≤ y ≤ m and all the servers between i and j are in the group and no other should be in the group.

Given the integer array workloads and integer difference, determine how many consecutive groups of servers meet the optimal performance criteria.

1Example 1

Input
load = [2, 4, 6], k = 2
Output
2
Explanation
Example 1 illustration
We return 2 based on the part highlighted in orange.
public int numberOfWellPerformingGroups(int[] load, int k) {
  // write your code here
}
Input

load

[2, 4, 6]

k

2

Output

2

Sign in to submit your solution.