Self Explanatory Java Solution
\nclass Solution {\n    public int[] avoidFlood(int[] rains) {\n        int[] ans = new int[rains.length];\n        Arrays.fill(ans, 1);\n        HashMap<Intege
```\nclass Solution {\n    public int[] avoidFlood(int[] rains) {\n        int[] ans = new int[rains.length];\n        Arrays.fill(ans, 1);\n        HashMap<Integer, Integer> map = new HashMap<>();\n        List<Integer> dry = new ArrayList<>();\n        for(int i = 0; i < rains.length; i++){\n            if(rains[i] > 0){\n                ans[i] = -1;\n                if(map.containsKey(rains[i])){\n                    int lastIndex = map.get(rains[i]);\n                    // No dry day exists\n                    if(dry.size() == 0){\n                        int arr[] = new int[0];\n                        return arr;\n                    }\n                    // int dryIndex = ls(dry, lastIndex, i);\n                    int dryIndex = bs(dry, lastIndex, i);\n                    // Can\'t dry this lake\n                    if(dryIndex == -1){\n                        int arr[] = new int[0];\n                        return arr;\n                    }\n                    ans[dryIndex] = rains[i];\n                    dry.remove(new Integer(dryIndex));\n                }\n                map.put(rains[i], i);\n            } else {\n                dry.add(i);   \n            }\n        }\n        return ans;\n    }\n    \n    // Binary Search to find first possible dry day\n    public int bs(List<Integer> l, int t1, int t2){\n        int index = -1;\n        int startIndex = 0, endIndex = l.size() - 1;\n        while(startIndex <= endIndex){\n            int mid = (startIndex + endIndex) / 2;\n            if(l.get(mid) <= t1){\n                startIndex = mid + 1;\n            } else {\n                if(l.get(mid) < t2){\n                    index = l.get(mid);\n                }\n                endIndex = mid - 1;\n            }\n        }\n        return index;\n    }\n    \n    // Linear Search to find first possible dry day\n    public int ls(List<Integer> l,int t1, int t2){\n        int index = -1;\n        for(int i = 0; i < l.size(); i++){\n            if(l.get(i) > t1 && l.get(i) < t2){\n                index = l.get(i);\n                break;\n            }\n        }\n        return index;\n    }\n}\n```
['Binary Tree', 'Java']