15% off all plans & roadmaps Use code
See plansProblem editorial
nums contains integers, and a subset is formed by choosing any collection of its elements, while preserving no ordering requirement. Each element may be chosen at most once, and the empty subset is allowed.
Sum of All Subset XOR Totals is a Backtracking Patterns problem, in the Subsets (Include/Exclude) subpattern. The pattern covers subsets, permutations, combinations, N-Queens, and word search
The reference solution runs in O(n) time and O(1) space.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Sum of All Subset XOR Totals is a Backtracking Patterns problem, in the Subsets (Include/Exclude) subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.