java
```\nclass Solution {\n    public int[] avoidFlood(int[] rains) {\n        int len = rains.length;\n        int[] res = new int[len];\n        TreeSet dryDays =
```\nclass Solution {\n    public int[] avoidFlood(int[] rains) {\n        int len = rains.length;\n        int[] res = new int[len];\n        TreeSet<Integer> dryDays = new TreeSet();\n        Map<Integer, Integer> fullLakes = new HashMap();\n        for(int i=0; i<len; i++){\n            if(rains[i]>0){\n                res[i] = -1;\n                if(fullLakes.containsKey(rains[i])){\n                    Integer dryDay = dryDays.higher(fullLakes.get(rains[i]));\n                    if(dryDay==null) \n                        return new int[0];\n                    else{\n                        dryDays.remove(dryDay);\n                        res[dryDay] = rains[i];\n                    }\n                }\n                fullLakes.put(rains[i], i);\n            }else{\n                res[i] = 1;\n                dryDays.add(i);\n            }\n        }\n        return res;\n    }\n}
[]