Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: What is the largest k such that 2^k divides 12!? Run the code.
Problem: What is the largest k such that 2^k divides 12!? Run the code.
n = 12
c = 0
p = 2
while p <= n:
c += n // p
p *= 2
print(c)What is printed?- A. 6
- B. 9
- C. 2
- D. 10
Correct answer: D. 10
Legendre: 12//2 + 12//4 + 12//8 = 6 + 3 + 1 = 10. Counting only the even numbers gives 6, stopping before 8 gives 9, and 2 counts the decimal trailing zeros of 12!.
More Coding Interview Problems questions
- Problem: What is the length of the longest common prefix of 'interview', 'internet' and 'interval'? Run the code. python import os…
- Problem: How many subsets of {1, ..., 7} contain no two numbers that differ by exactly 1? Run the code. python print(sum(1 for m in…
- Problem: What is the minimum number of moves to sort [4, 1, 3, 2] when one move takes any element to the front? Run the code (answer = n…
- Problem: What is the running time of Ford-Fulkerson when augmenting paths are found by DFS with integer capacities?
- Problem: Which algorithm finds the maximum subarray sum in O(n log n) by splitting the array and handling the crossing case?
- Problem: What does the Pisano period of m describe?