Simple solution using a Dictionary and a LinkedList.
The idea is to have a list with available days for drying, then when a lake is about to flood, we just have to find if there is a drying day BEFORE the previous
The idea is to have a list with available days for drying, then when a lake is about to flood, we just have to find if there is a drying day BEFORE the previous rain over the lake.\n1. if it does remove the day for the list and remove the lake from the full lakes set. \n2. if it doesn\'t the flooding is invevitable.\n\n\n```\npublic int[] AvoidFlood(int[] rains) {\n        var fullLakes = new Dictionary<int, int>(); // lake, full day\n        var dries = new LinkedList<int?>();\n        \n        var response = new int[rains.Length];\n        Array.Fill(response, 1);\n        \n        for (var d = 0; d < rains.Length; d++){\n            var lake = rains[d];\n            if (lake == 0) {\n                dries.AddLast(d);\n                continue;\n            }\n            \n            if (fullLakes.ContainsKey(lake)){                \n                var dry = dries.FirstOrDefault(i => i > fullLakes[lake]);\n                if (dry == null){\n                    return new int[0];\n                }\n                \n                response[dry.Value] = lake;\n                dries.Remove(dry);\n            }\n            \n            response[d] = -1;\n            fullLakes[lake] = d;\n        }\n        \n        \n        return response;\n    }  \n```
['Hash Table', 'Linked List']