Rust: HashSet & Radix Sort Solutions + Details
HashSet Solution:\n\nInserting to and querying a hash set have O(1) time complexity.\n\nWe can insert all elements in nums into our set in O(n) time.\nThen for 
**HashSet Solution**:\n\nInserting to and querying a hash set have `O(1)` time complexity.\n\nWe can insert all elements in `nums` into our set in `O(n)` time.\nThen for each number in our set that _is **not**_ part of a longer consecutive sequence, count how long the sequence is and return the maximum length we find.\n\nTo count the length of a sequence, we continuously query for the next ascending number until it\'s not found in our set, counting how many times we\'re able to do this.\nBecause we\'re _not_ considering sequences that are part of longer ones, the total time complexity of all these queries is `O(n)`.\n\n```rust\nimpl Solution {\n    pub fn longest_consecutive(nums: Vec<i32>) -> i32 {\n        let set: std::collections::HashSet<_> = nums.iter().collect();\n        set.iter()\n            .filter(|&&x| !set.contains(&(x - 1))) // ensure not part of a longer consecutive sequence\n            .map(|&&x| (x..).take_while(|x| set.contains(x)).count())\n            .max()\n            .unwrap_or(0) as _\n    }\n}\n```\n\n---\n\n**Base-10 LSD Radix Sort Solution**:\n\nUnlike comparison sorts that have `O(n*logn)` time complexity, distribution sorts such as radix sort have `O(n)` complexity.\n\nWe can sort `nums` using a distribution sort and count the length of the longest consecutive sequence while iterating through `nums`.\nBoth operations take `O(n)` time.\n\nThis example uses a base-10 radix sort (from the least-significant digits):\n\n```rust\nimpl Solution {\n    pub fn longest_consecutive(mut nums: Vec<i32>) -> i32 {\n        Self::radix_sort_base10(&mut nums);\n        nums.iter()\n            .zip(nums.iter().skip(1))\n            .scan(1, |n, (&a, &b)| {\n                *n = if a + 1 >= b { *n + b - a } else { 1 }; // +1 length if (a+1 == b), +0 if (a == b); otherwise reset length\n                Some(*n)\n            })\n            .max()\n            .unwrap_or(nums.len().min(1) as _)\n    }\n\n    fn radix_sort_base10(nums: &mut [i32]) {\n        let mut buckets = vec![vec![]; 20]; // for digits -9 to +9\n        for i in 0..10 {\n            nums.iter()\n                .for_each(|&x| buckets[10 + ((x / 10i32.pow(i)) % 10) as usize].push(x));\n            buckets\n                .iter()\n                .flat_map(|b| b.iter())\n                .zip(nums.iter_mut())\n                .for_each(|(&x, y)| *y = x);\n            buckets.iter_mut().for_each(|b| b.clear());\n        }\n    }\n}\n```
['Rust']