Javascript binary-search solution with brief comments
\nconst avoidFlood = (rains) => {\n    let n = rains.length;\n    let res = new Array(n).fill(-1);\n\n    let emptyLake = [];\n    let map = new Map();\n\n    f
```\nconst avoidFlood = (rains) => {\n    let n = rains.length;\n    let res = new Array(n).fill(-1);\n\n    let emptyLake = [];\n    let map = new Map();\n\n    for (let i = 0; i < n; i++) {\n        if (rains[i] > 0) { \n            if (map.has(rains[i])) {\n                let it = binary_search(emptyLake, map.get(rains[i])); // Find whether exists the "zero" right after previous filled lake \n\n                if (it[0] === -1) { // No "zero" is found\n                    return [];\n                }\n                res[it[0]] = rains[i];\n                emptyLake.splice(it[1], 1); // remove the "zero" when we use to clear current lake\n            }\n            map.set(rains[i], i);\n        } else { \n            emptyLake.push(i);\n        }\n    }\n\n    for (let i = 0; i < n; ++i) {\n        if (rains[i] === 0 && res[i] < 0) {\n            res[i] = 1;\n        }\n    }\n\n    return res;\n}\n\nconst binary_search = (array, target) => {\n    let start = 0, end = array.length - 1;\n\n    while (start + 1 < end) {\n        let mid = start + ((end - start) >> 1);\n\n        if (array[mid] >= target) {\n            end = mid;\n        } else {\n            start = mid;\n        }\n    }\n\n    if (array[start] >= target) {\n        return [array[start], start];\n    }\n\n    if (array[end] >= target) {\n        return [array[end], end];\n    }\n    \n    return [-1, -1];\n}\n```
['Binary Tree', 'JavaScript']