Data Structures & AlgorithmsModerateProduct Company SDE · CP practice
Problem: How many divisors does 10^6 have? Run the code.
Problem: How many divisors does 10^6 have? Run the code.
print(sum(1 for d in range(1, 10 ** 6 + 1) if (10 ** 6) % d == 0))What is printed?
- A. 36
- B. 49
- C. 13
- D. 7
Correct answer: B. 49
10⁶ = 2⁶ · 5⁶, so d = (6 + 1)(6 + 1) = 49. Forgetting the + 1 gives 36, adding the exponents gives 13, and 7 counts only powers of 10.
More Coding Interview Problems questions
- Problem: What is the largest prime below 1000? Run the code. python def isp(n): return n > 1 and all(n % d for d in range(2, int(n 0.5) +…
- Problem: How many paths go from (0,0) to (4,4) on a 5 x 5 grid using right and down moves while avoiding cell (2,2)? Run the DP. python n…
- Problem: How many ordered pairs (x, y) with 1 <= x < y <= 50 have x y a perfect square? Run the code. python print(sum(1 for x in range(1…
- Problem: How many ways are there to write 50 as an ordered sum a^2 + b^2 with a, b >= 0? Run the code. python print(sum(1 for a in…
- Problem: What is the maximum product of 4 consecutive elements of [1, 2, 3, 4, 5, 6]? Run the code. python a = [1, 2, 3, 4, 5, 6]…
- Problem: How many subsequences of 'abcabc' equal the string 'abc'? Run the DP. python s, t = 'abcabc', 'abc' dp = [1] + [0] len(t) for ch…