Server Selection
Learn this problemProblem statement
Duplicate note (July 2, 2026) ( ദ്ദി ˙ᗜ˙ ) : This problem is the same question as Get Max Servers. I merged this page's sighting dates into that version, so this page will not be updated anymore. If you want to practice, I recommend practicing Get Max Servers.
Amazon Web Services (AWS) provides highly scalable solutions for applications hosted on their servers. A company using AWS is planning to scale up horizontally and wants to buy servers from a list of available options.
Find the maximum number of servers (as a subsequence from the list) that can be rearranged so that the absolute difference between adjacent servers (including circular adjacency) is ≤ 1.
Conditions:
- A circular sequence is formed, so the first and last servers are also considered adjacent.
- A subsequence means elements can be removed, but you are free to rearrange the chosen elements.
Formal:
Given an array powers[] of n integers, find the maximum subsequence length m such that the chosen elements can be rearranged into a circular array a where:
abs(a[i] - a[i+1]) ≤ 1for all validi, andabs(a[m-1] - a[0]) ≤ 1wheremis the length of the subsequence.
Function
maxServers(powers: int[]) → intExamples
Example 1
powers = [4, 3, 5, 1, 2, 1]return = 4Constraints
powerscontainsnintegers.- The answer is the maximum number of elements that can be selected and rearranged into a valid circular arrangement.
- In the resulting circular arrangement,
abs(a[i] - a[i+1]) ≤ 1for all consecutive elements, andabs(a[m-1] - a[0]) ≤ 1, wheremis the length of the chosen arrangement.
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026