~/problems
Problems
Basics first, then the classics, then company-style assessments. Every problem has tests you run right here; multi-level ones unlock as you go. See the roadmap.
Bit manipulation (IP / CIDR)
IPv4 as a 32-bit int; lowest set bit for block sizes.
Notes
Recognise it when: IP addresses and CIDR, flags, powers of two, subsets.
- IPv4 as an int:
n = (n << 8) | int(octet); back again:(n >> shift) & 0xFF. - Lowest set bit:
x & -x, which is also the largest aligned block starting at x. - A
/lenblock has size1 << (32 - len), and its start must be a multiple of that size. - Is a power of two:
x and not (x & (x - 1)). Set-bit count:x.bit_count().
Gotchas: at x == 0 everything is aligned, so cap the block at the whole space.
14 problems
Interview roadmap
Bit manipulation Masks, shifts and IP-address arithmetic.
- Basics: IPv4 addresses as 32-bit integers basics easy
- Watering rota as weekday bitmasks easy
- Cover an IP range with CIDR blocks py · c++ · java medium
- IPv4 / CIDR iterator 5 levels OpenAI medium
- Ordered CIDR firewall 2 levels Databricks py · c++ · java medium
- Distinct goodness values CitadelScale AI py · c++ · java medium
- Palindromic paths toward the root Uber py · c++ · java hard
- Single Number py · c++ · java easy
- Number of 1 Bits py · c++ · java easy
- Counting Bits py · c++ · java easy
- Reverse Bits py · c++ · java easy
- Missing Number py · c++ · java easy
- Sum of Two Integers py · c++ · java medium
- Add Binary py · c++ · java easy