Data Structures & AlgorithmsModerateTCS NQT · bit tricks
Problem: What does the expression 'x & (x - 1)' clear in the binary representation of x?
- A. The highest set bit
- B. All bits
- C. The lowest set bit
- D. The sign bit only
Correct answer: C. The lowest set bit
Subtracting 1 flips the trailing zeros and the lowest set bit, and the AND removes that lowest set bit.
More Coding Interview Problems questions
- Problem: Which algorithm solves the 'minimum cost to connect all points' in the Euclidean plane with n points in O(n^2) time (dense graph)?
- Problem: What is the time complexity of building a trie for n strings of total length L?
- Problem: What is a 'bridge' in an undirected graph?
- Problem: Which algorithm finds the strongly connected components of a directed graph using a single DFS with a stack?
- Problem: What is the maximum number of edges in a bipartite graph on n vertices with sides of size n/2?
- Problem: Which problem is solved by Dijkstra's algorithm on a graph whose edge weights are small integers, using buckets (Dial's algorithm)?