JAVA EASY SOLUTION USING HASHMAP
```\nclass Solution {\n    public int[] avoidFlood(int[] rains) {\n        int[] ans=new int[rains.length];\n        Arrays.fill(ans,1);\n        TreeSet set=ne
```\nclass Solution {\n    public int[] avoidFlood(int[] rains) {\n        int[] ans=new int[rains.length];\n        Arrays.fill(ans,1);\n        TreeSet<Integer> set=new TreeSet<>();\n        HashMap<Integer,Integer> map=new HashMap<>();\n        for(int i=0;i<rains.length;i++){\n            if(rains[i]==0){\n                set.add(i);\n            }\n            else{\n                if(map.containsKey(rains[i])){\n                    Integer zero=set.ceiling(map.get(rains[i]));\n                     if (zero == null) return new int[0];\n                    ans[zero]=rains[i];\n                    set.remove(zero);\n                }\n                ans[i]=-1;\n                map.put(rains[i],i);\n            }\n        }\n        return ans;\n    }\n}
['Ordered Set', 'Java']