Data Structures & AlgorithmsModerateProduct Company SDE · CP practice
Problem: How many integers in [1, 300] are multiples of 6 but not of 9? Run the code.
Problem: How many integers in [1, 300] are multiples of 6 but not of 9? Run the code.
print(sum(1 for x in range(1, 301) if x % 6 == 0 and x % 9 != 0))What is printed?
- A. 34
- B. 45
- C. 50
- D. 17
Correct answer: A. 34
Multiples of 6 (50) minus multiples of lcm(6, 9) = 18 (16) gives 34. Using 6 × 9 = 54 gives 45, 50 ignores the condition, and subtracting multiples of 9 gives 17.
More Coding Interview Problems questions
- Problem: How many ordered triples (a, b, c) of positive integers satisfy a + b + c = 7? Run the code. python print(sum(1 for a in range(1…
- Problem: What is the largest possible value of gcd(a, b) when a + b = 60 and a != b with a, b positive? Run the code. python from math…
- Problem: What is the complexity of a single query in a sparse-table range minimum structure?
- Problem: What is the purpose of a 'suffix link' in Ukkonen's or Aho-Corasick's construction?
- Problem: Which property does an 'order statistics' tree support in addition to search?
- Problem: What is the time complexity of the 'Mo's algorithm with updates' (time dimension added) in terms of n and q?