注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
和这个帖子一样的题
1. reduce gifts
determine the minimum num of items to remove from an array of prices so that the sum of prices of any k items does not exceed a threshold.
Note: if the number of items in the list is less than k, then there is no need to remove any more items.
ex:
prices = [3, 2, 1, 4, 6, 5]
k = 3
threshold = 14
The sum of prices for every 3 items must not be more than 14. The sum of prices of the last three item is 6 + 5+ 4 = 15. the item price
6 can be removed.so the list leave[3, 2, 1, 4, 5]. No 3 items' prices sum to greater than 14. Only 1 item needs to removed.
return the min number of items to remove from the list
prices = [9, 6, 7, 2, 7, 2]
k = 2
threshold = 13
return 2
prices = [9,205; 2 seconds, request 2 is removed because it is processed, request 3 is served.
The number of requests in the queue is 1. queue = [3].
- time = 3 seconds, request 3 is removed because it is processed. The number of requests in the queue is 0. queue = [empty].
The answer is [4, 2, 1, 0].
Constraints:
1 ≤ n ≤ 10^5
1 ≤ wait[i] ≤ 10^5
Input: wait = [4,4,4]
Output: [3, 2, 1, 0] |