[Python] Concise Hashmap greedy solution
Idea: Keep track of the set of un-used dry lands so far, upon flooding (i.e second time we see a lake number), try to dry it with earliest dry land that falls b
Idea: Keep track of the set of un-used dry lands so far, upon flooding (i.e second time we see a lake number), try to dry it with earliest dry land that falls between the first time we see the lake and current index.\n```\nclass Solution:\n    def avoidFlood(self, rains):\n        dry_lands = []    # Index of dry lands that are not used yet\n        last_flood = dict()    # index of previous flood\n        res = []      # result list to return\n        for i,r in enumerate(rains):\n            if r == 0:\n                dry_lands.append(i)\n                res.append(1)\n            else:\n                if r in last_flood: # If flood occurs, try the first dry land up until this point\n                    dried = False\n                    for j,dl in enumerate(dry_lands):\n                        if dl > last_flood[r]:\n                            res[dl] = r\n                            last_flood[r] = i\n                            del dry_lands[j]\n                            dried = True\n                            break\n                    if not dried:\n                        return []\n                else:\n                    last_flood[r] = i\n                res.append(-1)\n        return res\n```
['Python']