Java || Easy Approach with Explanation || HashMap || TreeSet
\nclass Solution \n{//T -> O( N log N) S -> O( N )\n    public int[] avoidFlood(int[] rains)\n    {           \n        int[] ans= new int[rains.length];//resul
```\nclass Solution \n{//T -> O( N log N) S -> O( N )\n    public int[] avoidFlood(int[] rains)\n    {           \n        int[] ans= new int[rains.length];//resultant array \n        \n        Arrays.fill(ans, 1);//default case if dry day is not utilised \n        \n        Map<Integer, Integer> map= new HashMap<>();//lake -- index \n        \n        TreeSet<Integer> dry= new TreeSet<>();//like min heap//next dry day index//DNSO\n        \n        for(int i= 0; i< rains.length; i++) //linearly traversing the Array \n        {\n            if(rains[i] == 0) \n                dry.add(i);//dry day index \n            else \n           {\n                if(map.containsKey(rains[i]))//lake already present with previous index\n                {\n                    //next dry day for the paricular lake, if not present then the city will be in flooded \n                    Integer nextDry= dry.ceiling(map.get(rains[i]));//O(log N)//in min heap we require O(N) by contains method//internal mechanism Red Black Tree//ceiling return the next greater of the specified value \n                    \n                    if(nextDry == null)//no dry day means overflow, city is flooded\n                        return new int[0];\n                    \n                    ans[nextDry]= rains[i];//putting the lake which is dried in the dry day \n                    \n                    dry.remove(nextDry);//dry day utilised, dried a lake//O(log N)\n                }\n                ans[i]= -1;//ans[i] == -1 if rains[i] > 0.//normal raining day \n\t\t\t\tmap.put(rains[i], i);//putting the the lake and their corresponding index to the map \n            }\n        }\n        return ans;//returning the resultant Array \n    }\n}//Please do Upvote, it helps a lot\n```
['Tree', 'Heap (Priority Queue)', 'Ordered Set', 'Java']