Python solution with detailed comments, no extra package used
class Solution:\n\n    def avoidFlood(self, rains: List[int]) -> List[int]:\n        d = set()\n        full = set()\n        ans = [1]*len(rains) # we set 1 si
class Solution:\n\n    def avoidFlood(self, rains: List[int]) -> List[int]:\n        d = set()\n        full = set()\n        ans = [1]*len(rains) # we set 1 since if no need to dry a lake in a sunny day, fix it to 1\n        l = [] # stores the index that rains[i] has appeared before \n        for i in range(len(rains)):\n            if rains[i]!=0 and rains[i] in d: #rains[i] appeared before current index\n                l.append(i)\n            else:\n                d.add(rains[i])\n        del d\n\n        for i in range(len(rains)): \n            if rains[i]:\n                if rains[i] in full:\n                    return []\n                full.add(rains[i])\n                ans[i] = -1 #rainy day is set to -1\n            else: # for the sunny day, we search the l and find the first index such that l[j] is full\n                for j in range(len(l)):\n                    if rains[l[j]] in full:\n                        index = l.pop(j)\n                        ans[i] = rains[index]\n                        full.remove(rains[index])\n                        break        \n        return ans
['Python']