Data Structures & AlgorithmsModerateProduct Company SDE · CP practice
Problem: How many distinct values does a XOR b take for a, b in {0, 1, 2, 3}? Run the code.
Problem: How many distinct values does a XOR b take for a, b in {0, 1, 2, 3}? Run the code.
print(len({a ^ b for a in range(4) for b in range(4)}))What is printed?- A. 4
- B. 5
- C. 3
- D. 6
Correct answer: A. 4
XOR over the 2-bit values is a group, so all four values 0..3 appear.
More Coding Interview Problems questions
- Problem: What is the sum of all integers in [1, 200] that are both odd and multiples of 5? Run the code. python print(sum(x for x in…
- Problem: What is the maximum number of distinct characters in a substring of length 4 of 'abcabcabc'? Run the code. python s = 'abcabcabc'…
- Problem: How many ways are there to tile a 2 x 6 board with 2 x 1 dominoes? Run the DP. python f = [1, 1] for n in range(2, 7)…
- Problem: What is the minimum number of edges to remove from a 5-vertex complete graph to leave a spanning tree? Run the code (answer = E…
- Problem: How many integers from 1 to 10^6 have exactly one set bit (power of two)? Run the code. python print(sum(1 for x in range(1, 10 6…
- Problem: What is the maximum number of points on a line among (0,0), (1,1), (2,2), (3,5), (4,4) (collinear with the diagonal)? Run the…