[Python] ✓ greedy backtracking one-pass O(N²)
python\ndef avoidFlood(self, rains):\n    full = {}                                       # hashtable of challenges to cause flood\n\t\n\tdry = []              
```python\ndef avoidFlood(self, rains):\n    full = {}                                       # hashtable of challenges to cause flood\n\t\n\tdry = []                                        # array of opportunities to avoid flood\n\t                                                # note: sortable C++ set or Java TreeSet superior to array in use\n\t\n    for day, lake in enumerate(rains):              # one-pass iteration\n\t                                                # outer O(N)\n        if not lake:\n            dry.append(day)                         # store indeterminate opportunity in ascending order\n\t\t\t\n            rains[day] = 1                          # stationary trial\n            continue\n        if lake in full:                            # optimal opportunity consumption \n\t\t                                            # against determinate challenge to cause flood\n\t\t\n            i = bisect.bisect_left(dry, full[lake]) # optimal greedy search\n\t\t\t                                        # inner O(log(N)) from binary search on array\n\t\t\t\t\t\t\t\t\t\t\t\t\t# note: O(log(N)) as well in case of C++ set or Java TreeSet \n\t\t\t\t\t\t\t\t\t\t\t\t\t\n            if i == len(dry): return []             # flood unavoidable result\n\t\t\t\n            rains[dry.pop(i)] = lake                # backtracking to reconciliation\n\t\t\t                                        # inner O(N) due to removal of array element\n\t\t\t\t\t\t\t\t\t\t\t\t\t# note: O(1) in case of C++ set or Java TreeSet \n\t\t\t\t\t\t\t\t\t\t\t\t\t\n        full[lake] = day                            # store indeterminate challenge for later lookup\n\t\t\n        rains[day] = -1                             # stationary result\n\t\t\n    return rains                                    # flood avoidable result\n```
[]