[Java] TreeSet and a Map- Idea is to fill the blanks later when you encounter a possible flood
```\nclass Solution {\n    public int[] avoidFlood(int[] rains) {\n        int zeroes = 0;\n        Map rained = new HashMap<>();\n        TreeSet dry = new Tre
```\nclass Solution {\n    public int[] avoidFlood(int[] rains) {\n        int zeroes = 0;\n        Map<Integer, Integer> rained = new HashMap<>();\n        TreeSet<Integer> dry = new TreeSet<>();\n        int result[] = new int[rains.length];\n        for(int i =0; i<rains.length; ++i) {\n            if(rains[i] == 0) {\n                dry.add(i);\n                result[i] = 1;\n            } else {\n                if(!rained.containsKey(rains[i])) {\n                    result[i] = -1;\n                    rained.put(rains[i], i);\n                } else {\n                    Integer fill = dry.ceiling(rained.get(rains[i]) +1);\n                    if(fill == null)\n                        return new int[0];\n                    result[fill] = rains[i];\n                    result[i] = -1;\n                    dry.remove(fill);\n                    rained.put(rains[i], i);\n                }\n            }\n        }\n        return result;\n    }\n}
[]