Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: How many distinct values does x mod 12 take over the numbers x in [1, 1000] that are not divisible by 4? Run the code.
Problem: How many distinct values does x mod 12 take over the numbers x in [1, 1000] that are not divisible by 4? Run the code.
print(len({x % 12 for x in range(1, 1001) if x % 4 != 0}))What is printed?- A. 9
- B. 6
- C. 12
- D. 3
Correct answer: A. 9
x not divisible by 4 means x mod 12 avoids 0, 4, 8, leaving 9 residues, and all appear by 1000. Also removing multiples of 3 gives 6, 12 counts every residue, and 3 counts the excluded ones.
More Coding Interview Problems questions
- Problem: What is the length of the longest palindromic substring of 'abacdcaba'? Run the code. python s = 'abacdcaba' best = 0 for c in…
- Problem: How many integers in [1, 10000] have a digit sum that is divisible by 7? Run the code. python print(sum(1 for x in range(1…
- Problem: How many integer solutions (a, b) with 1 <= a <= b <= 20 satisfy a b = 36? Run the code. python print(sum(1 for a in range(1, 21)…
- Problem: What is the length of the longest common subsequence of 'abcdef' and 'acebdf'? Run the DP. python a, b = 'abcdef', 'acebdf' dp =…
- Problem: What is the number of subsets of {1, 2, ..., 8} whose elements sum to a multiple of 8? Run the code. python print(sum(1 for m in…
- Problem: How many pairs (i < j) of [1, 4, 9, 16, 25] have a[j] - a[i] divisible by 3? Run the code. python a = [1, 4, 9, 16, 25]…