Rust HashMap and BTreeSet Solution
rust\nuse std::collections::{HashMap, BTreeSet};\nuse std::ops::Bound::*;\n\nimpl Solution {\n    pub fn avoid_flood(rains: Vec<i32>) -> Vec<i32> {\n        let
```rust\nuse std::collections::{HashMap, BTreeSet};\nuse std::ops::Bound::*;\n\nimpl Solution {\n    pub fn avoid_flood(rains: Vec<i32>) -> Vec<i32> {\n        let mut dry_lakes = BTreeSet::new();\n        let mut lakes = HashMap::new();\n        let mut ans = vec![1; rains.len()];\n        for (i, r) in rains.into_iter().enumerate() {\n            if r == 0 {\n                dry_lakes.insert(i);\n                continue;\n            }\n            if lakes.contains_key(&r) {\n                if let Some(j) = dry_lakes.range((Excluded(lakes[&r]), Excluded(i))).next().copied() {\n                    ans[j] = r;\n                    dry_lakes.remove(&j);\n                } else {\n                    return vec![];\n                }\n            }\n            lakes.insert(r, i);\n            ans[i] = -1;\n        }\n        ans\n    }\n}\n```
['Rust']