dsa1 min read
Minimum XOR Sum of Two Arrays — Bitmask DP
Assign each element of nums1 to exactly one element of nums2 to minimize XOR sum. Classic assignment bitmask DP: dp[mask] = min XOR sum.
Read →
webcoderspeed.com
1276 articles
Assign each element of nums1 to exactly one element of nums2 to minimize XOR sum. Classic assignment bitmask DP: dp[mask] = min XOR sum.
Generate n-bit Gray code sequence where adjacent codes differ by exactly 1 bit. Formula: gray(i) = i ^ (i >> 1).
Find all 10-letter DNA sequences that appear more than once. Use rolling hash (4-bit per char) or set of seen substrings.
Count words that contain puzzle[0] and only letters from puzzle. Encode words as bitmasks, for each puzzle enumerate its subsets containing puzzle[0].
Find max product of lengths of two words with no common letters. Encode each word as bitmask; two words share letters if AND != 0.