Skip to content

Practice Avoid Flood in The City

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1488
LeetCode Problem

Avoid Flood in The City

Problem Statement

All 10^9 lakes start empty. On day i, a positive rains[i] fills that lake; filling an already full lake causes a flood. When rains[i] = 0, choose one lake to empty, including an already empty lake if desired. Return one entry per day: -1 on rainy days and the chosen lake number on dry days. Any flood-free schedule is valid; return [] if none exists.

Source: Avoid Flood in The City on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
rains = [1,2,3,4]
Output
[-1,-1,-1,-1]

# Example 2

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

# Example 3

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

Constraints

1 <= rains.length <= 10^5
0 <= rains[i] <= 10^9

Related LeetCode Problems

Practice more problems similar to Avoid Flood in The City.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.