using Hashmap and treeSet simple and fast solution easy to understand
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int[] avoidFlood(int[] rains) {\n        HashMap<Integer,Integer> map=new HashMap<>();\n        TreeSet<Integer> dry=new TreeSet<>();\n\n        int n=rains.length;\n        int[] res=new int[n];\n\n        for(int i=0;i<n;i++){\n            if(rains[i]==0){\n                dry.add(i);\n                res[i]=1; \n            }\n            else{\n                if(map.containsKey(rains[i])){\n                   Integer availZero=dry.ceiling(map.get(rains[i]));\n                   if(availZero==null){\n                       return new int[0];\n                   }\n                   res[availZero]=rains[i];\n                   dry.remove(availZero);\n\n                }\n                res[i]=-1;\n                map.put(rains[i],i);\n            }\n        }\n        return res;\n    }\n}\n```
['Java']