C++ O(nlogn) with Explanation
Idea is to maintain a set of the indexes of zero and a hashmap of indexes of rain.\nWhenever we find a zero in the rains vector, we push it into zero set which 
Idea is to maintain a set of the indexes of zero and a hashmap of indexes of rain.\nWhenever we find a zero in the rains vector, we push it into zero set which maintain the indexes of zero.\nIf the rains[i] is non-zero, then we see if we have already filled the lake.\nIf it is already filled, we try to empty it.\nWe find the last index of rains[i].\nThen we find the index of the lake we want to empty which is the next bigger element than the last index of rains[i]. (As we can\'t empty the lake before it is filled).\nIf, no such zero slot is found, the lake will be flooded, hence return an empty result.\nOnce zero is filled, erase it from the set.\n\n\n```\nvector<int> avoidFlood(vector<int>& rains) {\n        vector<int> res(rains.size(),-1);\n        unordered_map<int, int> m;\n        set<int> zero;\n        for(int i =0; i < rains.size(); ++i)\n        {\n            if(rains[i] == 0)\n            {\n                zero.insert(i);\n                res[i] = 1;\n            }\n            else\n            {\n                if(m.count(rains[i]))\n                {\n                    int lastIndex = m[rains[i]];\n                    auto zeroIndex = zero.upper_bound(lastIndex);\n                    if(zeroIndex == zero.end())\n                    {\n                        return {};\n                    }\n                    res[*zeroIndex] = rains[i];\n                    zero.erase(zeroIndex);\n                }\n                m[rains[i]] = i;\n            }\n        }\n        return res;\n    }\n\t
['Tree', 'C', 'Ordered Set']