Data Structures & AlgorithmsModerateTCS NQT · number theory
Problem: What does the following print?
Problem: What does the following print?
from math import lcm print(lcm(*range(1, 11)))
- A. 3628800
- B. 5040
- C. 2520
- D. 720
Correct answer: C. 2520
The LCM of 1..10 takes the highest power of each prime up to 10: 2^3 * 3^2 * 5 * 7 = 2520. The product 10! = 3628800 is the trap of multiplying instead.
More Coding Interview Problems questions
- Problem: How many integers from 1 to 100 have exactly 3 positive divisors? python print(sum(1 for x in range(1, 101) if sum(1 for d in…
- Problem: Piles of stones are 3, 4 and 5. Two players alternately remove any positive number of stones from one pile, and whoever takes the…
- Problem: A subtraction game lets a player remove 1, 3 or 4 stones. Let g(n) be the Grundy number (mex of the Grundy values reachable in…
- Problem: Two fair six-sided dice are rolled. What is the expected value of the larger of the two faces (the maximum)?
- Problem: Words apple, app, apt, bat, banana are stored in a trie that keeps a count of words passing through each node. What does the code…
- Problem: The longest subarray with equally many 0s and 1s of a = [0, 1, 0, 0, 1, 1, 0] is needed. Run the prefix-balance code and print…