InterviewStack.io LogoInterviewStack.io

Bit Manipulation and Mathematics Questions

Focuses on algorithmic and mathematical techniques that use bit level operations and discrete mathematics. Includes bitwise operators and tricks such as masking, shifting, counting bits, parity, extracting or setting fields, fast multiplication or division by powers of two, and common bit hacks. Also covers number theory and modular arithmetic fundamentals used in algorithm design, combinatorics basics for counting and enumerations, constructive mathematical reasoning, and designing creative problem solving approaches that combine bit manipulation with mathematical insight. Performance implications and complexity analysis of bit based solutions are also included.

EasyTechnical
87 practiced
You must implement feature flags for up to 60 independent boolean flags per user. Propose an efficient storage and API design using a single 64-bit bitmask per user: show how to set/clear/query flags, serialize to API responses, migrate to add new flags, and compare trade-offs with storing flags as a dictionary of booleans in a database.
EasyTechnical
92 practiced
Write a Python function to count the number of set bits in a 64-bit unsigned integer. Provide two implementations: (1) a straightforward method using the n & (n-1) loop, and (2) an optimized approach suitable for many repeated queries (e.g., byte lookup table or SWAR/Hamming weight). Discuss time, space trade-offs, and which approach you would use in a high-throughput service.
HardTechnical
92 practiced
Solve subset sum for n <= 40 and target S up to 1e12 using meet-in-the-middle: split array into two halves, enumerate all subset sums for each half, sort one list, and use two-pointer or binary search to count combinations summing to S. Then discuss how a bitset-based DP (bitset convolution) might be used when S is small and how to combine approaches for mixed constraints.
MediumTechnical
94 practiced
All elements in an integer array appear exactly twice except for two elements that appear only once. Implement an O(n) time and O(1) extra space C++ function to find those two unique numbers. Explain the XOR partitioning trick you use and why it separates the two singletons.
HardSystem Design
86 practiced
Design a compact bitfield encoding for network packet headers that packs variable-length fields into minimal bits, supports optional fields via presence flags, aligns for 64-bit processing efficiency, and allows backward-compatible extensions. Specify encoding rules, parsing algorithm in C (low-branch approach), endian handling, versioning strategy, and how to handle future additions of fields.

Unlock Full Question Bank

Get access to hundreds of Bit Manipulation and Mathematics interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.