Minimum Servers for an Exact Load
Updated
Problem statement
You are given an array server of request-handling capacities and an integer expected_load. Every capacity is a power of two.
Choose the minimum number of servers whose capacities sum to exactly expected_load.
- Each server may be selected at most once.
- Different servers may have the same capacity.
- The selected capacities must equal the load exactly; exceeding it is not allowed.
Return the minimum number of selected servers, or -1 if no selection is possible.
Function
getMinServers(expected_load: int, server: int[]) → intExamples
Example 1
expected_load = 3server = [1,1,2,4]return = 2Select the server of capacity 2 and either server of capacity 1. Their total capacity is 1 + 2 = 3. No single server has capacity 3, so two servers are necessary and sufficient.
Example 2
expected_load = 4server = [1,1,1]return = -1All three servers together provide capacity 3, which is less than 4. No selection can meet the load.
Constraints
1 <= server.length <= 10^51 <= server[i] <= 10^9- Every capacity is a power of two.
1 <= expected_load <= 10^9
More JP Morgan Chase Online Assessment questions
- Find Total CostOA · Seen Oct 2026
- Minimum Meeting RoomsOA · Seen Oct 2026
- Count Dropped RequestsOA · Seen Oct 2026
- Maximize Minimum Deployment DifficultyOA · Seen Oct 2026
- Task SchedulingOA · Seen Oct 2026
- Substring RemovalOA · Seen Oct 2026
- Maximum Game Board ScoreOA · Seen Sep 2026
- Minimum Digit Changes Between String HalvesOA · Seen Sep 2026
- Same Substring Within BudgetOA · Seen Sep 2026
- Invert Ad Visibility BitsOA · Seen Aug 2026
Similar questions at other companies
- Minimize the Maximum Array ElementChubb · OAChubb interview questions
- Minimum Halvings for Alternating ParityIBM · OAIBM interview questions
- Server SelectionPoint72 · OAPoint72 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
- Minimum Operations to Sort with Rotations Then SwapsBank of New York Mellon · OA