Python HashMap + SortedList Solution | Faster than 91% | Commented | Simple
\nfrom sortedcontainers import SortedList\n\nclass Solution:\n    def avoidFlood(self, rains: List[int]) -> List[int]:\n        # dryDays = Set of available day
```\nfrom sortedcontainers import SortedList\n\nclass Solution:\n    def avoidFlood(self, rains: List[int]) -> List[int]:\n        # dryDays = Set of available days that can be used for drying a full lake.\n        dryDays, numDays = SortedList(), len(rains)\n        # fullLakes is a hashMap which stores Lake number -> day on which it became full.\n        fullLakes, ans = defaultdict(int), []\n        for idx in range(numDays):\n            if rains[idx] == 0:\n                # This day can be used as a day to dry some lake.\n                dryDays.add(idx)\n                # Any number would be ok. This will get overwritten eventually.\n                # If it doesn\'t get overwritten, its totally ok to dry a lake\n                # irrespective of whether it is full or empty.\n                ans.append(1)\n            # Rained in rains[i]-th lake.\n            else:\n                lake = rains[idx]\n                if lake in fullLakes:\n                    # We must dry this lake before it rains in this lake.\n                    # So find a day in "drydays" to dry this lake. Obviously, that day must be\n                    # a day that is after the day on which the lake was full.\n                    # i.e. if the lake got full on 7th day, we must find a dry day that is \n                    # greater than 7.\n                    dryDayIdx = dryDays.bisect_left(fullLakes[lake])\n                    # If there is no available dry day to dry the lake, flooding is inevitable.\n                    if dryDayIdx == len(dryDays):\n                        return []\n                    # Great, we found a day which we can use to dry this lake.\n                    dryDay = dryDays[dryDayIdx]\n                    # Overwrite the "1" and dry "lake"-th lake instead.\n                    ans[dryDay] = lake\n                    # We dried "lake"-th lake on "dryday", and we can\'t use the same day to \n                    # dry any other lake, so remove the day from the set of available drydays.\n                    dryDays.remove(dryDay)\n                # Update that the "lake" became full on "i"-th day.\n                fullLakes[lake] = idx\n                # As the problem statement expects.\n                ans.append(-1)\n        return ans\n```
['Python']