Python 3 solution with intuitive explanation
What this solution does is iterates through the rains list and keep track of 2 things: \n1. A list of the index of all available dry days from most oldest to ne
What this solution does is iterates through the rains list and keep track of 2 things: \n1. A list of the index of all available dry days from most oldest to newest \n2. A hashtable of lakes containing the most recent day each lake got rained on \n\nin the event that lake i is zero, we set ans[i] to 1 (the description does not say this, but it must be done for a correct solution). We then add that zero to the end of the zeros list \n\nin the event that rains[i] is not in our current lake, we add it to our lakes hashtable with the index as its value \n\nin the event that rains[i] is in our hashtable (meaning the lake will flood if it is not cleared) we go through our list of zeros from oldest to newest (so we dont interfere with future clearings) and find the first one which is greater than the value of lakes[rains[i]]. \n\nWe then set ans[valid zero] to the lakes number(meaning we cleared this lake on this day), and remove the zero from our zeros list. Next, we set the lake\'s value in our lake hashtable to the current index, because this is now the most recent day that the lake got rained on \n\nIf no valid zero is found, we return []\n\n```\nclass Solution:\n    def avoidFlood(self, rains: List[int]) -> List[int]:\n        lakes = dict() \n        ans = [-1] * len(rains) \n        zeros = [] \n        \n        for i in range(0, len(rains)):\n            if rains[i] == 0:\n                zeros.append(i)\n                ans[i] = 1\n            \n            elif rains[i] in lakes:  \n                if len(zeros) == 0:\n                    return []\n                \n                for j in range(0, len(zeros)):\n                    if zeros[j] > lakes[rains[i]]:\n                        ans[zeros[j]] = rains[i]\n                        lakes[rains[i]] = i \n                        del zeros[j]\n                        break \n                    \n                    if j == len(zeros) - 1:\n                        return []\n                                   \n            elif rains[i] not in lakes:\n                lakes[rains[i]] = i \n                \n        return ans\n        \n```
[]