Company: Jp morgan_31march
Difficulty: medium
You are given n storage partitions. For each partition i: used[i] is the amount of space currently used totalCapacity[i] is the maximum space it can hold You may move data between partitions, but no partition may exceed its total capacity. Your task is to: Rearrange the data so that it is stored using the fewest possible partitions Return the minimum number of partitions required Example 1 Input: n = 5 partitions, used = [3, 2, 1, 3, 1], totalCapacity = [3, 5, 3, 5, 5] Output: 2 Explanation: 1. Move the data from the first partition to the second partition. 2. Combine the data in the third through fifth partitions into either the fourth or fifth partition. Example 2 Input: n = 3 partitions, used = [1, 2, 3], totalCapacity = [3, 3, 3] Output: 2 Explanation: Combine the data in the first two partitions into either one. The third partition remains. Constraints 1 ≤ n ≤ 1000 1 ≤ used[i] ≤ 1000 1 ≤ totalCapacity[i] ≤ 1000 Test Case Input Format The first line contains an integer n, the size