Server Selection
Updated
Problem statement
You are given an array server, where server[i] is the request-handling capacity of one server. Every capacity is a power of 2. You are also given a target load expected_load.
Return the minimum number of servers whose capacities sum to exactly expected_load. Return -1 if no such selection exists.
For this exercise, assume the following selection rules:
- Each array element represents a separate server that may be selected at most once. Servers with equal capacities remain separate choices.
- A selected server contributes its entire capacity; capacities cannot be split or partially used. A total greater than
expected_loadis not valid. - If
expected_loadis0, the empty selection is valid and the answer is0.
The callable minimumServers(server, expected_load) returns only the minimum count, not the selected indices. The target uses a long integer in Java and a long long integer in C++.
Function
minimumServers(server: int[], expected_load: long) → intExamples
Example 1
server = [1,2,8,4,2]expected_load = 13return = 3Select capacities 8, 4, and 1, totaling 13. The two largest servers total only 12, so fewer than three cannot work.
Example 2
server = [2,2,8]expected_load = 7return = -1Every possible total is even, so no selection totals 7. The server with capacity 8 cannot be used partially.
Example 3
server = [16,8,4]expected_load = 0return = 0Select no servers to meet the zero load.
Constraints
1 <= server.length <= 100000.- For this exercise, assume
server[i] = 2^bfor an integerbwith0 <= b <= 30. - For this exercise, assume
0 <= expected_load <= 10^15.
More Point72 interview questions
- Maximize Array Beauty After DeletionsOA · Seen Aug 2026
- Simulate a Deterministic Finite AutomatonOA · Seen Aug 2026
- Initial Public OfferingOA · Seen Jul 2026
- Test the HypothesisOA · Seen Jul 2026
- Get Triplet CountOA · Seen Jul 2026
- Internet Service Provider Monthly ReportOA · Seen Jul 2026
- Lexicographically Smallest String After Substring OperationOA · Seen May 2026
- Best Time to Buy and Sell Stock IIPHONE SCREEN · Seen Aug 2026
- Find Minimum in a Rotated Sorted ArrayPHONE SCREEN · Seen Aug 2026
- Generate an Optimal Portfolio Trading ReportPHONE SCREEN · Seen Apr 2026
Similar questions at other companies
- Minimize the Maximum Array ElementChubb · OAChubb interview questions
- Minimum Halvings for Alternating ParityIBM · OAIBM interview questions
- Minimum Servers for an Exact LoadJP Morgan Chase · OAJP Morgan Chase interview questions
- Get Max Or SumMicrosoft · OAMicrosoft interview questions
- Maximize PartitionsAmazon · OA
- Fewest Steps to Build an Array from ZerosExpedia · OAExpedia interview questions
- Maximum XOR Elimination ScoreRippling · OARippling interview questions
- Minimum Cost for a Target WeightPace Stock Broking Services · PHONE SCREEN
- Minimum Row Deletions to Prevent a Target ORInMobi · ONSITE INTERVIEWInMobi interview questions
- Earn the Most 🐝Capital One · OACapital One interview questions