Minimum Memory for Hard Drives
Updated
Problem statement
You are distributing games to N children. There are m games in total, and games[i] is the memory size of game i. You prepare N hard drives of the same size and give one to each child. Every child must receive at least one game, and all games must be distributed.
The games are handed out in the given order: each child receives one consecutive group of games, and each hard drive must hold the total size of its child's games.
Find the minimum memory capacity that each of the N hard drives needs so that the games can be distributed this way.
Function
minimumMemory(games: int[], N: int) → int Complete the function minimumMemory in the editor.
minimumMemory has the following parameters:
int[] games: the memory size of each gameint N: the number of children (and hard drives)
Returns int: the minimum memory capacity of each hard drive
Examples
Example 1
games = [6, 7, 10, 12, 1]N = 3return = 13Split the games, in order, into the groups [6, 7], [10] and [12, 1]. Their sums are 13, 10 and 13, so the largest is 13 and each hard drive needs 13 memory.
A capacity of 12 is not enough. The 12 cannot share a drive with its neighbour 10 (sum 22) or with 1 (sum 13), so the 12 needs its own drive and the 1 needs its own drive. One drive is left for 6 + 7 + 10 = 23, which is more than 12. So the answer is 13.
Constraints
1 <= N <= m <= 10^5, wheremis the length ofgames1 <= games[i] <= 10^4
More Amazon interview questions
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximal SquareONSITE INTERVIEW · Seen Nov 2026
- Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Diagonal Traversal of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
- Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
- Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
Similar questions at other companies
- Capacity to Ship Packages Within DaysMicrosoft · OA · ONSITE INTERVIEWMicrosoft interview questions
- Rock JumpingIMC Trading · OAIMC Trading interview questions
- Minimize Maximum Group DifferenceDRW · OADRW interview questions
- Array NullificationQRT · OA
- Minimum-Cost Solar Rooftop AllocationDeloitte · OADeloitte interview questions
- Three-Part Partition with Minimum Largest RangeLSEG · OALSEG interview questions
- K-Means ClusteringAtlassian · OAAtlassian interview questions
- Get Minimum Development TimeSalesforce · OASalesforce interview questions
- Job ExecutionMathWorks · OAMathWorks interview questions
- Police Station 🚓The D.E. Shaw Group · OAThe D.E. Shaw Group interview questions