Data Structures & AlgorithmsModerateAmazon · Microsoft OA
Problem: A permissions engine isolates bits of a mask.
Problem: A permissions engine isolates bits of a mask.
x = 88 print(x & -x, x & (x - 1))What is printed?
- A. 8 87
- B. 8 80
- C. 16 80
- D. 1 80
Correct answer: B. 8 80
88 = 1011000₂. x & −x keeps only the lowest set bit (1000₂ = 8), and x & (x − 1) clears that bit, leaving 1010000₂ = 80. Both rely on two's complement: −x = ~x + 1.
More Coding Interview Problems questions
- Problem: Rearrange the digits of a version list into the next lexicographically greater permutation. python def nxt(a): i = len(a) - 2…
- An analytics service holds a static array of n = 10⁵ integers and must answer q = 10⁶ queries 'minimum of a[l..r]' as fast as possible…
- Given n = 5 × 10⁴ integers, count pairs i < j with a[i] > 2·a[j]. Which approach is correct and efficient?
- Problem: Evaluate a reverse-Polish expression. The specification says division must truncate toward zero (as in C or Java). python def…
- Problem: Sum the minimum of every contiguous subarray using a monotonic stack (previous-less and next-less-or-equal boundaries). python…
- Problem: Count the distinct non-empty substrings of a short string. python s = "ababa" print(len({s[i:j] for i in range(len(s)) for j in…