C++ solution with O(nlogn)
From the description, the lakes are infinite which means range from 1 to 10^5. That means we can not use an array to store the lakes, HashMap is a good way.  We
From the description, the lakes are infinite which means range from 1 to 10^5. That means we can not use an array to store the lakes, `HashMap` is a good way.  We can use a variable `unordered_map<int, int> last_rain` to store the last rain lake, and a set variable `sun` to store the sunny day. At iterating the rains, if today is sun day, we can mark it in `sun`, if today is rain day, we can mark it in `last_rain`, but if the lake is full, we should do something to avoid flood:\n1. find the first sun day from `sun` from the last rain day to today.\n2. if we can not find the sun day from step1, we should return a empty array to express no way to avoid flood\n\n```cpp\n#include<set>\n\nclass Solution {\npublic:\n    vector<int> avoidFlood(vector<int>& rains) {\n        std::set<int> sun;\n        unordered_map<int, int> last_rain;\n        vector<int> ans(rains.size(), -1);\n        for (int i=0; i<rains.size(); ++i) {\n            // mark the sun day\n            if (rains[i] == 0) {\n                sun.insert(i);\n                ans[i] = 1;\n            } else {\n                if (last_rain.count(rains[i]) > 0) {\n                    // the lake is full, we should do sth...\n                    // find the first sun day after the last rain day\n                    auto it = sun.upper_bound(last_rain[rains[i]]);\n                    // can not find the way to dry the lake\n                    if (it == std::end(sun)) {\n                        return {};\n                    }\n                    ans[*it] = rains[i];\n                    sun.erase(it);\n                }\n                // mask the last rain day\n                last_rain[rains[i]] = i;\n            }\n        }\n        return ans;\n    }\n};\n```
['C']