Tap here to switch tabs
Problem
Submissions

Problem: Avoid Flood in The City

med
30 min
Try to solve the Avoid Flood in The City problem.

Statement

You are given an integer array rains representing a weather forecast across several days, where each lake is initially dry.

On day i:

  • If rains[i] > 0, it rains over lake rains[i]. If lake rains[i] is already full, a flood occurs.

  • If rains[i] == 0, no rain occurs, and you may choose one lake to drain completely.

Return an array ans of the same length as rains such that:

  • ans[i] == −1-1 if rains[i] > 0.

  • ans[i] is the number of the lake chosen to be drained if rains[i] == 0. If no lake needs to be drained, any valid lake number greater than 00 may be chosen.

If it is impossible to avoid a flood, return an empty array. If multiple valid configurations exist, return any of them.

Constraints:

  • 1≤1 \leq rains.length ≤105\leq 10^5

  • 0≤0 \leq rains[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Avoid Flood in The City

med
30 min
Try to solve the Avoid Flood in The City problem.

Statement

You are given an integer array rains representing a weather forecast across several days, where each lake is initially dry.

On day i:

  • If rains[i] > 0, it rains over lake rains[i]. If lake rains[i] is already full, a flood occurs.

  • If rains[i] == 0, no rain occurs, and you may choose one lake to drain completely.

Return an array ans of the same length as rains such that:

  • ans[i] == −1-1 if rains[i] > 0.

  • ans[i] is the number of the lake chosen to be drained if rains[i] == 0. If no lake needs to be drained, any valid lake number greater than 00 may be chosen.

If it is impossible to avoid a flood, return an empty array. If multiple valid configurations exist, return any of them.

Constraints:

  • 1≤1 \leq rains.length ≤105\leq 10^5

  • 0≤0 \leq rains[i] ≤109\leq 10^9