Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: What is the number of distinct values of floor(n / 2) + floor(n / 3) for 1 <= n <= 50? Run the code.
Problem: What is the number of distinct values of floor(n / 2) + floor(n / 3) for 1 <= n <= 50? Run the code.
print(len({n // 2 + n // 3 for n in range(1, 51)}))What is printed?- A. 41
- B. 34
- C. 43
- D. 50
Correct answer: B. 34
The set of n//2 + n//3 for n = 1..50 has 34 values; some jumps skip values. 41 assumes every value up to the maximum is hit, 43 adds the distinct counts of n//2 and n//3 separately, and 50 assumes one value per n.
More Coding Interview Problems questions
- Problem: What is the largest sum of a subarray of length at least 2 in [4, -1, 5, -6, 3, 2]? Run the code. python a = [4, -1, 5, -6, 3, 2]…
- Problem: How many paths of length exactly 4 go from vertex 0 to vertex 0 in the complete graph K3? Run the code (walks allowed to repeat…
- Problem: How many ways are there to choose 4 distinct numbers from 1..12 with sum 26? Run the code. python from itertools import…
- Problem: What is the sum of the digits of the number 2^64? Run the code. python print(sum(int(c) for c in str(2 64))) What is printed?
- Problem: How many integers x in [1, 2000] satisfy x^2 ≡ x (mod 10)? Run the code. python print(sum(1 for x in range(1, 2001) if (x x - x)…
- Problem: How many inversions does the array [2, 3, 8, 6, 1] have? Run the code. python a = [2, 3, 8, 6, 1] print(sum(1 for i in…