As reported: JPMorgan Chase SE3 (Q4 2025), R1 after a project discussion, first of two coding questions: storage partitions with
usedandcapacityarrays; rearrange the data to use the minimum number of partitions.
There are n storage partitions. Partition i currently holds used[i] units of data and can hold at most capacity[i] units. You may move data between partitions in any way — a partition's data can be split across several others. After rearranging, a partition that holds any data counts as used.
Return the minimum number of partitions needed to hold all the data.
Example 1
used = [3,2,1,3,1]
capacity = [3,5,3,5,5] -> 2
There are 10 units in total; two partitions of capacity 5 hold them all, and no single partition can.
Example 2
used = [2,1,2]
capacity = [5,3,4] -> 1
All 5 units fit in the first partition.
Constraints: 1 ≤ n ≤ 10^5; 1 ≤ used[i] ≤ capacity[i] ≤ 10^9. The total of used can exceed 32 bits.
Code runner format: two lines, used and capacity as JSON arrays. Implement minPartitions(used, capacity); the harness prints the number of partitions.