Data Structures & AlgorithmsModerateCodeforces Div2 B · bit tricks
Problem: How many trailing zero bits does 40 have in binary? Run the code.
Problem: How many trailing zero bits does 40 have in binary? Run the code.
print((40 & -40).bit_length() - 1)What is printed?
- A. 3
- B. 2
- C. 4
- D. 5
Correct answer: A. 3
40 = 101000 in binary, so the lowest set bit is at position 3. The expression 40 & -40 isolates it.
More Coding Interview Problems questions
- Problem: How many pairs (i < j) of [2, 4, 6, 8] have gcd exactly 2? Run the code. python from itertools import combinations from math…
- Problem: Starting at (0,0) in the grid below, how many cells are reachable by 4-directional moves through '.' cells? Run the BFS. python…
- Problem: What is the minimum number of coins from {1, 5, 10, 25} summing to 63? Run the DP. python INF = 10 9 d = [0] + [INF] 63 for v in…
- Problem: Climbing stairs 0 to 5 with steps of 1 or 2, but stair 3 is broken and cannot be stood on. How many ways are there to reach stair…
- Problem: Is 'cdeab' a rotation of 'abcde'? Check with the substring test below. What is printed? python s, t = 'abcde', 'cdeab'…
- Problem: Find the minimum cost of a Hamiltonian tour starting and ending at city 0, with symmetric distances D =…