Description

Given rains array, 0 means dry day (empty a full lake), positive means lake that fills. Return which lake to empty to avoid flooding.

Examples

Input:rains = [1,2,0,0,2,1]
Output:[-1,-1,2,1,-1,-1]
Explanation:

Dry lakes 2,1 to avoid flood.

Input:rains = [1,0,2,3,0,1,0]
Output:[-1,1,-1,-1,2,-1,3]
Explanation:

Lake 1 fills on day 1. Day 2 is dry, so drying lake 1. Lakes 2 and 3 fill on days 3-4. Lake 1 fills again on day 6, but already dried it on day 2, so no flood. Day 5 is dry, so drying lake 2. Day 7 is dry, so drying lake 3.

Input:rains = [2,1,0,1]
Output:[]
Explanation:

Lake 2 fills on day 1, lake 1 fills on day 2. Day 3 is dry, but it is possible to only dry one lake. Lake 1 fills again on day 4, causing a flood since it wasn't dried. Return empty array to indicate impossible.

Constraints

  • 1 ≤ rains.length ≤ 10⁵

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!