C++ Using unordered map and set + explanation
\n#define DRY  0\n#define ANY_LAKE 1\n// The solution is to match dry day by the order it become full again\n// By selecting the first dry day available after i
```\n#define DRY  0\n#define ANY_LAKE 1\n// The solution is to match dry day by the order it become full again\n// By selecting the first dry day available after it become full before\n// We dont have to empty lakes that appear only once even if we can\nclass Solution {\npublic:\n    vector<int> avoidFlood(vector<int>& rains) \n    {\n        vector<int> result(rains.size(),-1);\n        unordered_map<int,int> lakes_full;\n        set<int> dry_days;\n        for (int i=0; i<rains.size(); i++)\n        {\n            if (rains[i] == DRY)\n            {\n                result[i] = ANY_LAKE;  // mark as default day as default\n                dry_days.insert(i);\n            }\n            else\n            {\n                int lake = rains[i];\n                auto prior_full_day = lakes_full.find(lake);\n                // Check if lake is already full\n                if (prior_full_day != lakes_full.end())\n                {   // Check for the first dry day after first full\n                    int day = prior_full_day->second;\n                    auto first_dry_day = dry_days.lower_bound(day);\n                    if (first_dry_day  == dry_days.end())\n                    {   // return fail result\n                        result.clear();\n                        break;  \n                    }\n                    // Update dry day with lake (change from default)\n                    result[*first_dry_day]  =  lake;\n                    // Remove dry day form available days list\n                    dry_days.erase(first_dry_day);\n                }\n                // Update lakes full for current day\n                lakes_full[lake] = i;\n            }\n        }\n        return result;        \n    }\n};\n```
[]