Minimum Racks for Server Resources
Updated
Problem statement
You are given n indivisible servers. Server i requires bandwidth[i] units of bandwidth and power[i] units of power.
Every rack has a bandwidth capacity of rackBandwidthCapacity and a power capacity of rackPowerCapacity. A group of servers can share one rack only when both of these conditions hold:
- The sum of their bandwidth requirements is at most
rackBandwidthCapacity. - The sum of their power requirements is at most
rackPowerCapacity.
Assign every server to exactly one rack and return the minimum number of racks required.
Function
minimumRacks(bandwidth: int[], power: int[], rackBandwidthCapacity: int, rackPowerCapacity: int) → intExamples
Example 1
bandwidth = [4,4,2]power = [3,2,3]rackBandwidthCapacity = 6rackPowerCapacity = 5return = 2The server with requirements (4, 2) can share a rack with the server requiring (2, 3). Their totals are (6, 5). The remaining server uses a second rack.
Example 2
bandwidth = [3,3,3,3]power = [4,4,4,4]rackBandwidthCapacity = 6rackPowerCapacity = 8return = 2Each rack can hold exactly two servers, so two racks are sufficient and necessary.
Example 3
bandwidth = [2,2,2]power = [6,6,6]rackBandwidthCapacity = 10rackPowerCapacity = 10return = 3Bandwidth would allow the servers to share, but any pair needs 12 power units. Each server therefore needs its own rack.
Constraints
1 <= bandwidth.length == power.length <= 15.1 <= bandwidth[i] <= rackBandwidthCapacity <= 10^6.1 <= power[i] <= rackPowerCapacity <= 10^6.- Every server fits in an otherwise empty rack.
More Google Phone Screen questions
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Minimum Cost for a Target WeightPace Stock Broking Services · PHONE SCREEN
- Optimal Account BalancingAmazon · ONSITE INTERVIEW
- Delete K Subsets for Maximum ScoreRubrik · OARubrik interview questions
- Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
- Maximum Index-Weighted Sum with Disjoint SwapsVisa · OAVisa interview questions
- Distinct OR Values of Increasing SubsequencesScale AI · OAScale AI interview questions
- Smallest Sufficient TeamExpedia · ONSITE INTERVIEWExpedia interview questions
- Vehicle Builds for Required Terrain (Game Adaptation)Roblox · OARoblox interview questions
- Bitwise XOR SubsequencesJP Morgan Chase · OAJP Morgan Chase interview questions
- Bitwise XOR SubsequencesGoldman Sachs · OAGoldman Sachs interview questions