C# Solution
\npublic class Solution\n{\n    public int[] AvoidFlood(int[] rains) \n    {\n        var zeros = new List<int>();\n        var prev = new Dictionary<int, int>(
```\npublic class Solution\n{\n    public int[] AvoidFlood(int[] rains) \n    {\n        var zeros = new List<int>();\n        var prev = new Dictionary<int, int>();\n        var result = Enumerable.Repeat(-1, rains.Length).ToArray();\n        \n        for(int i = 0; i < rains.Length; i++)\n        {\n            var lake = rains[i];\n            if(rains[i] == 0)\n            {\n                zeros.Add(i);\n                result[i] = 1;\n            }\n            else\n            {\n                if(!prev.ContainsKey(lake))\n                    prev[lake] = i;\n                else\n                {\n                    var prevIndex =  prev[lake];\n                    var index = zeros.BinarySearch(prevIndex + 1);\n                    if(index < 0)\n                        index = ~index;\n                    if(index == zeros.Count)\n                        return new int[0];\n                    prev[lake] = i;\n                    result[zeros[index]] = lake;\n                    zeros.RemoveAt(index);\n                }\n            }\n        }\n        \n        return result;\n    }\n}\n```
[]