dsa1 min read
Gray Code — Binary XOR Construction
Generate n-bit Gray code sequence where adjacent codes differ by exactly 1 bit. Formula: gray(i) = i ^ (i >> 1).
Read →
1575 articles
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.
Complete bit manipulation cheatsheet: all critical tricks, bitmask DP patterns, XOR properties, complexity table, and problem index.