Rust | Iterative DFS | With Comments
Build bitsets of all strings that do not contain duplicate characters. Perform a DFS to find the union of non-overlapping bitsets with the highest bit count.\n\
Build bitsets of all strings that do not contain duplicate characters. Perform a DFS to find the union of non-overlapping bitsets with the highest bit count.\n\nImplementation details:\n* I like early returns when possible, so the body of the `filter_map` becomes a little bulkier than computing the bitset as the full union first and then checking if the number of bits of the bitset is equal to the string length.\n* I prefer iterative solutions over recursion, and in this case it is pretty straight-forward. We split the search tree into one branch that includes the current set (`sets[i]`) if we can (if we can\'t, we don\'t branch, and that prunes the search), and one branch that doesn\'t.\n\n```\nimpl Solution {\n    pub fn max_length(arr: Vec<String>) -> i32 {\n        let sets = arr.into_iter().filter_map(|s| {\n            let mut bitset = 0;\n            for bm in s.bytes().map(|b| 1 << (b - b\'a\')) {\n                if bitset & bm != 0 {\n                    return None;\n                } else {\n                    bitset |= bm;\n                }\n            }\n            Some(bitset)\n        }).collect::<Vec<_>>();\n\n        let mut stack = vec![(0_i32, 0)];\n        let mut rez = 0;\n\n        while let Some((bitset, i)) = stack.pop() {\n            if i == sets.len() {\n                rez = rez.max(bitset.count_ones());\n            } else {\n                if bitset & sets[i] == 0 {\n                    stack.push((bitset | sets[i], i + 1));\n                }\n                stack.push((bitset, i + 1));\n            }\n        }\n        rez as _\n    }\n}\n```
['Rust']