Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: What is the maximum value of a[i] XOR a[j] over i < j for a = [3, 10, 5, 25, 2, 8, 17]? Run the code.
Problem: What is the maximum value of a[i] XOR a[j] over i < j for a = [3, 10, 5, 25, 2, 8, 17]? Run the code.
a = [3, 10, 5, 25, 2, 8, 17] print(max(a[i] ^ a[j] for i in range(len(a)) for j in range(i + 1, len(a))))What is printed?
- A. 29
- B. 28
- C. 42
- D. 25
Correct answer: B. 28
The best pair is 25 ⊕ 5 = 28 (11001 ⊕ 00101 = 11100). Using OR gives 25 | 5 = 29, using + gives 42, and 25 assumes the maximum element alone wins.
More Coding Interview Problems questions
- Problem: How many subarrays of [1, -1, 1, -1, 1] have sum 0? Run the prefix-count code. python from collections import Counter a = [1, -1…
- Problem: What is the number of paths from (0,0) to (4,4) using right and up moves that never touch the diagonal cells (i, i) except at the…
- Problem: What is the number of integers in [1, 10000] that are perfect squares and also end in the digit 9? Run the code. python…
- Problem: How many ways are there to split the string '1234' into two non-empty parts whose integer values are both divisible by 3? Run the…
- Problem: How many non-empty subsets of {1, 2, 3, 4, 5, 6, 7, 8} have a sum that is a multiple of 4? Run the code. python from itertools…
- Problem: What is the minimum number of operations to make the array [5, 1, 4] strictly increasing where one operation increments any…