✅ beats 100% Java code
Java Code\n\nclass Solution {\n    private LinkedList<Integer> dryDays;\n\n    public int[] avoidFlood(int[] rains) {\n        int n = rains.length;\n        in
# Java Code\n```\nclass Solution {\n    private LinkedList<Integer> dryDays;\n\n    public int[] avoidFlood(int[] rains) {\n        int n = rains.length;\n        int[] res = new int[n];\n        Arrays.fill(res, 1);\n        dryDays = new LinkedList<>();\n        for (int i = 0; i < n; i++) {\n            if (rains[i] == 0) dryDays.add(i);\n            else res[i] = -1;\n        }\n        Map<Integer, Integer> tracker = new HashMap<>();\n        for (int i = 0; i < n; i++) {\n            if (rains[i] == 0) continue;\n            if (tracker.containsKey(rains[i])) {\n                int dryDay = findDryDay(tracker.get(rains[i]), i);\n                if (dryDay == -1) {\n                    return new int[0];\n                }\n                res[dryDay] = rains[i];\n            }\n            tracker.put(rains[i], i);\n        }\n        return res;\n    }\n\n    private int findDryDay(int prev, int current) {\n        Iterator<Integer> iterator = dryDays.iterator();\n        while (iterator.hasNext()) {\n            int day = iterator.next();\n            if (day < current && day > prev) {\n                iterator.remove();\n                return day;\n            }\n        }\n        return -1;\n    }\n}\n```
['Array', 'Hash Table', 'Binary Search', 'Greedy', 'Java']