Simple O(NLogN) 82.5%
We have 1 unordered_map full where full[lake_no] -- stores the last day when that lake was filled completely\nThe set dry stores list of dry days when emptying 
We have 1 unordered_map **full** where **full[lake_no] -- stores the last day when that lake was filled completely**\nThe set **dry** stores list of dry days when emptying of some lakes can be performed. When we reach an element a[i] it means that lake a[i] is going to be filled today so we search if there exists some dry day between last time when that lake was filled and curr day. **So we search for the dry day just greater than full[a[i]]**. If such day exists then the current lake can be emptied on that day. else there will be flood. \n```\nclass Solution {\npublic:\n    vector<int> avoidFlood(vector<int>& a) {\n        int i=0,n=a.size();\n        vector<int> ans(n,-1);\n        unordered_map<int,int> full;\n        set<int> dry;\n        for(i=0;i<n;i++){\n            if(a[i]==0){\n                dry.insert(i);\n                continue;\n            }\n            if(full.find(a[i])!=full.end()){\n                auto it=dry.lower_bound(full[a[i]]); // next dry day \n\t\t\t\t// checking if there was a dry day someday after the curr lake was filled previously\n                if(it==dry.end()) // if there does not exists any dry day between last time the lake was filled and curr day\n                    return {};\n                ans[*it]=a[i];\n                dry.erase(it);\n            }\n            full[a[i]]=i;\n        }\n\t\t// it does matter what we do on remaining dry days\n        for(auto e:dry){\n            ans[e]=1; // fill it with any +ve integer\n        }\n        return ans;\n    }\n};\n```
['C', 'C++']