The Avoid Flood in The City interview question presents a scenario with several lakes. On a rainy day, rain falls over a specific lake. If it rains on a lake that is already full, it floods. On a sunny day, you can choose one full lake to dry. You are given an array representing the weather for each day (0 for sunny, x > 0 for rain on lake x). The goal is to find a schedule for drying lakes that avoids all floods. This Avoid Flood in The City coding problem is a greedy strategy challenge with future-lookahead logic.
Google and Amazon ask this to test advanced data structure usage. It requires a Greedy approach: when it's sunny, which lake should you dry? The best choice is the lake that is scheduled to receive rain the soonest. This tests your ability to use Hash Maps for tracking and Binary Search or Heaps to find the optimal dry day.
This uses the Array, Hash Table, Binary Search, Heap (Priority Queue), Greedy interview pattern.
rains = [1, 2, 0, 1, 2]
When you have a limited resource (sunny days) that must be used to prevent a future failure (flood), always look for the "earliest upcoming failure" to prioritize your resource allocation.