java simple solution with linewise comments
\nclass Solution {\n    public int[] avoidFlood(int[] rains) {\n         HashMap<Integer, Integer> map = new HashMap<>();\n        TreeSet<Integer> treeSet = ne
```\nclass Solution {\n    public int[] avoidFlood(int[] rains) {\n         HashMap<Integer, Integer> map = new HashMap<>();\n        TreeSet<Integer> treeSet = new TreeSet<>();\n        \n        int[] ans= new int[rains.length];\n        \n        // Importaint for passing test case like 0, 2, 0, 2;\n        for(int i = 0; i < ans.length; i++) if (rains[i] == 0) ans[i] = 1;\n        \n        for(int i = 0; i < rains.length; i++){\n            \n            if (rains[i] == 0){\n                // dry day information store in treeset.\n                treeSet.add(i);   \n            }\n            else{\n                int lakei = rains[i];\n                // lake vs Day map\n                if (map.containsKey(lakei)){\n                    // getting the day lake got filled with rain.\n                    int day = map.get(lakei);\n                    \n                    // getting the nearest upcomming dry day from treeSet;\n                    if (treeSet.ceiling(day) != null){\n                        int dryDay = treeSet.ceiling(day);\n                        // after getting dryday remove this day from treeset.\n                        treeSet.remove(dryDay);\n                        // on this dry day i am going to dry my lake.\n                        ans[dryDay] = lakei;\n                        \n                        // now lake can fill once again after drying\n                        map.put(lakei, i);\n                        ans[i] = -1;\n                    }\n                    else{\n                        // no ceiling dryday found.\n                        return new int[0];\n                    }\n                }\n                else{\n                    map.put(lakei, i);\n                    ans[i] = -1;\n                }\n            }\n        }\n        \n        return ans;\n    \n    }\n}**if it is useful upvote please**\n```
['Tree', 'Ordered Set']