[C++] || Set + Map
Store indices where rains[i] == 0 , in  set st.\n\n Keep a map indices to keep track of which lake is already filled .\n\n When encountering a lake, if it is al
* Store indices where `rains[i] == 0` , in  set `st`.\n\n* Keep a map `indices` to keep track of which lake is already filled .\n\n* When encountering a lake, if it is already filled, then it had to be dried. But on which Day???\n\n* `PrevDay` stores the last seen index of same lake. Therefore, it is only possible to empty this lake if there is a zero after `prevDay` index. Which we can easily check with `upper_bound` in set `st`.\n\n* We get the index of zero after `prevDay`, Now remove this index from set `st`. and now the last seen index of the lake will be present `i`. Update it.\n\n* Now, on the day where we can empty any lake But ans still contains -1, replace it with 1.\n\n```\nclass Solution {\npublic:\n    vector<int> avoidFlood(vector<int>& rains) {\n        vector<int> ans(rains.size() , -1) ;\n        unordered_map<int,int> indices ; //store the lake and its index \n        set<int> st ; //stores the indices of zeros \n        \n        for(int i = 0 ; i < rains.size() ; ++i ){\n            if(!rains[i]) st.insert(i) ;\n            else{\n                if(indices.find(rains[i]) == end(indices)) indices[rains[i]] = i ;\n                else{\n                    int prevDay = indices[rains[i]] ;\n                    auto it = st.upper_bound(prevDay) ;\n                    if(it == end(st)) return {} ;\n                    ans[*it] = rains[i] ;\n                    indices[rains[i]] = i ;\n                    st.erase(it);\n                }\n            }\n        }\n        \n        for(int i = 0 ; i < ans.size(); ++i ){\n            if(!rains[i] and ans[i] == -1) ans[i] = 1 ;\n        }\n        return ans ;\n    }\n};\n```
['Binary Search', 'C']