Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: What is the smallest positive integer that is divisible by every integer from 1 to 12? Run the code.
Problem: What is the smallest positive integer that is divisible by every integer from 1 to 12? Run the code.
from math import lcm print(lcm(*range(1, 13)))What is printed?
- A. 2310
- B. 4620
- C. 27720
- D. 13860
Correct answer: C. 27720
lcm(1..12) = 2³ · 3² · 5 · 7 · 11 = 27720. Multiplying only the primes gives 2310, using 2² · 3 gives 4620, and missing the 2³ from 8 gives 13860.
More Coding Interview Problems questions
- Problem: Which technique gives the number of distinct subarrays of an array of length n in O(n log n) time using a suffix structure?
- Problem: Which statement about the Knuth optimization for interval DP is correct when its monotonicity conditions hold?
- Problem: What is the time complexity of building a suffix array with prefix doubling and radix sort?
- Problem: Which problem is solved by the Aho-Corasick automaton?
- Problem: Which claim about the centroid decomposition of a tree is correct?
- Problem: What is the complexity of answering distance queries on a tree after O(n log n) preprocessing with the sparse-table LCA?