Loading...
You are given a list of integers fills, one entry per day. There are containers numbered 1, 2, 3, and so on, and every container starts out empty.
On day i:
fills[i] > 0, container fills[i] is filled. If that container was already full, it overflows.fills[i] is 0, you empty exactly one container. Emptying a container that is already empty is allowed and changes nothing.Return a list ans of the same length as fills. On a day that fills a container, ans[i] is -1. On any other day ans[i] is the container you empty, and you must pick it by this rule:
1.If a container overflows on some day, return an empty list.
Input: fills = [1,2,3,4]
Output: [-1,-1,-1,-1]
Explanation: Every day fills a container, and no container is filled twice, so nothing overflows and every entry is -1.
Input: fills = [1,2,0,0,2,1]
Output: [-1,-1,2,1,-1,-1]
Explanation: On day 2 containers 1 and 2 are both full. Container 2 is filled again on day 4 and container 1 on day 5, so container 2 comes soonest and is emptied. On day 3 only container 1 is full and filled again later, so it is emptied. Days 4 and 5 then fill empty containers.
Input: fills = [1,2,0,1,2]
Output: []
Explanation: On day 2 containers 1 and 2 are both full, and container 1 is filled again on day 3 while container 2 is filled on day 4, so container 1 is emptied. Day 3 fills container 1 again. On day 4 container 2 is filled while it is still full, so it overflows.
Input: fills = [7,0,0]
Output: [-1,1,1]
Explanation: Container 7 is full from day 0 on, but it is never filled again, so it is not one of the containers the rule looks at. On both day 1 and day 2 there is no container that is full and filled again later, so the answer names container 1 each time.
fills.lengthfills[i] ≤109