InterviewStack.io LogoInterviewStack.io

Bit Manipulation Questions

Working directly with binary representations: bitwise operators, masking, shifting, bit counting, and integer-encoding tricks. Covers using bit-level operations for compact state, fast arithmetic, and low-level optimization. Especially relevant where memory and cycles are constrained.

HardTechnical
77 practiced

Implement a C++ solution to find the maximum XOR of any two numbers in an array using a binary trie (bitwise trie). Provide code for building the trie for 32-bit integers, querying maximum XOR for each number, and analyze time/memory complexity. Discuss memory optimizations if the array is very large and trade-offs with sorting-based methods.

MediumTechnical
91 practiced

Generate the n-bit Gray code sequence (reflective Gray code) using bitwise operations. Write a function in Python or C++ that returns the k-th Gray code for given k and n (i.e., convert binary k to Gray code), and one that converts back from Gray to binary. Explain correctness.

EasyTechnical
95 practiced

In C, implement integer division by a power of two using bit shifting: int divideByPowerOfTwo(int x, int k). Explain how arithmetic right shift differs from truncating division when x can be negative, and show how to adjust the algorithm to match C's integer division semantics (round toward zero) for negative values without using the division operator.

HardTechnical
69 practiced

Discuss and implement an optimized bitset DP approach for maximum independent set / maximum clique on graphs up to n<=50 using bit-parallel branch-and-bound. Describe adjacency as 64-bit bitmasks, candidate set intersections with &, ordering heuristics, coloring bounds for pruning, and how bit operations accelerate backtracking. Provide complexity analysis and practical tips for making it fast.

HardTechnical
78 practiced

Explain how to use SIMD instructions to compute popcount across a large buffer of 64-bit integers. Provide a high-level algorithm that uses vectorized byte-wise lookup (PSHUFB) or AVX512_VPOPCNTDQ where available, discuss alignment and tail handling, and explain trade-offs between using lookup tables vs dedicated popcount instructions.

Unlock Full Question Bank

Get access to all Bit Manipulation interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.