Rust - Sliding Window
Solution - github\n\nProblem List\n#SlidingWindow - github\n#Subarray - github\n\n\nuse std::collections::HashSet;\n/// @author: Leon\n/// https://leetcode.com/
Solution - [github](https://github.com/An7One/lc_soln_rust_leon/tree/main/src/leetcode/lvl2/lc1695)\n\n<b>Problem List</b>\n#SlidingWindow - [github](https://github.com/An7One/leetcode-problems-by-tag-an7one/tree/main/txt/by_technique/n_pointers/by_pointer_amount/2_pointers/sliding_window)\n#Subarray - [github](https://github.com/An7One/leetcode-problems-by-tag-an7one/blob/main/txt/by_data_structure/array/by_data_structure/subarray.txt)\n\n```\nuse std::collections::HashSet;\n/// @author: Leon\n/// https://leetcode.com/problems/maximum-erasure-value/\n/// Time Complexity:    O(`len_n`)\n/// Space Complexity:   O(`len_n`)\n/// Reference:\n/// https://leetcode.com/problems/maximum-erasure-value/discuss/978552/Java-O(n)-Sliding-Window-%2B-HashSet\nimpl Solution {\n    pub fn maximum_unique_subarray(nums: Vec<i32>) -> i32 {\n        let len_n: usize = nums.len();\n        let mut seen: HashSet<i32> = HashSet::new();\n        let mut lo: usize = 0;\n        let mut hi: usize = 0;\n        let mut sum: i32 = 0;\n        let mut most: i32 = 0;\n        while hi < len_n{\n            if seen.insert(nums[hi]){\n                sum += nums[hi];\n                most = std::cmp::max(most, sum);\n                hi += 1;\n            }else{\n                sum -= nums[lo];\n                seen.remove(&nums[lo]);\n                lo += 1;\n            }\n        }\n        most\n    }\n}\n```\n\n```\nuse std::collections::HashSet;\n/// @author: Leon\n/// https://leetcode.com/problems/maximum-erasure-value/\n/// Time Complexity:    O(`len_n`)\n/// Space Complexity:   O(`len_n`)\nimpl Solution {\n    pub fn maximum_unique_subarray(nums: Vec<i32>) -> i32 {\n        let len_n: usize = nums.len();\n        let mut seen: HashSet<i32> = HashSet::new();\n        let mut lo: usize = 0;\n        let mut most: i32 = 0;\n        let mut sum: i32 = 0;\n        for hi in 0..len_n {\n            sum += nums[hi];\n            while lo < hi && seen.contains(&nums[hi]) {\n                sum -= nums[lo];\n                seen.remove(&nums[lo]);\n                lo += 1;\n            }\n            seen.insert(nums[hi]);\n            most = std::cmp::max(most, sum);\n        }\n        most\n    }\n}\n```\n\n```\n/// @author: Leon\n/// https://leetcode.com/problems/maximum-erasure-value/\n/// Time Complexity:    O(`len_n`)\n/// Space Complexity:   O(`RANGE`)\nimpl Solution {\n    pub fn maximum_unique_subarray(nums: Vec<i32>) -> i32 {\n        const RANGE: usize = 10e4 as usize + 7;\n        let len_n: usize = nums.len();\n        let mut freqs: Vec<u16> = vec![0; RANGE];\n        let mut lo: usize = 0;\n        let mut most: i32 = 0;\n        let mut sum: i32 = 0;\n        for hi in 0..len_n {\n            sum += nums[hi];\n            freqs[nums[hi] as usize] += 1;\n            while lo < hi && freqs[nums[hi] as usize] > 1 {\n                sum -= nums[lo];\n                freqs[nums[lo] as usize] -= 1;\n                lo += 1;\n            }\n            most = std::cmp::max(most, sum);\n        }\n        most\n    }\n}\n```\n\n```\nuse std::collections::HashMap;\n/// @author: Leon\n/// https://leetcode.com/problems/maximum-erasure-value/\n/// Time Complexity:    O(`len_n`)\n/// Space Complexity:   O(`len_n`)\nimpl Solution {\n    pub fn maximum_unique_subarray(nums: Vec<i32>) -> i32 {\n        let len_n: usize = nums.len();\n        let mut num_to_freq: HashMap<i32, u16> = HashMap::new();\n        let mut lo: usize = 0;\n        let mut most: i32 = 0;\n        let mut sum: i32 = 0;\n        for hi in 0..len_n {\n            sum += nums[hi];\n            *num_to_freq.entry(nums[hi]).or_default() += 1;\n            while lo < hi && *num_to_freq.get(&nums[hi]).unwrap() > 1 {\n                sum -= nums[lo];\n                *num_to_freq.entry(nums[lo]).or_default() -= 1;\n                lo += 1;\n            }\n            most = std::cmp::max(most, sum);\n        }\n        most\n    }\n}\n```\n\n```\nuse std::collections::HashSet;\n/// @author: Leon\n/// https://leetcode.com/problems/maximum-erasure-value/\n/// Time Complexity:    O(`len_n`)\n/// Space Complexity:   O(`len_n`)\nimpl Solution {\n    pub fn maximum_unique_subarray(nums: Vec<i32>) -> i32 {\n        let len_n: usize = nums.len();\n        let mut seen: HashSet<i32> = HashSet::new();\n        let mut lo: usize = 0;\n        let mut hi: usize = 0;\n        let mut most: i32 = 0;\n        let mut sum: i32 = 0;\n        while hi < len_n {\n            while hi < len_n && seen.insert(nums[hi]) {\n                sum += nums[hi];\n                hi += 1;\n            }\n            most = std::cmp::max(most, sum);\n            while hi < len_n && lo < hi && seen.contains(&nums[hi]) {\n                seen.remove(&nums[lo]);\n                sum -= nums[lo];\n                lo += 1;\n            }\n            if hi < len_n{\n                sum += nums[hi];\n                seen.insert(nums[hi]);\n            }\n            hi += 1;\n        }\n        most\n    }\n}\n```
['Sliding Window', 'Rust']