Data Structures & AlgorithmsModerateProduct Company SDE · CP practice
Problem: How many integers in [1, 500] are multiples of 3 but not of 5? Run the code.
Problem: How many integers in [1, 500] are multiples of 3 but not of 5? Run the code.
print(sum(1 for x in range(1, 501) if x % 3 == 0 and x % 5 != 0))What is printed?
- A. 166
- B. 100
- C. 167
- D. 133
Correct answer: D. 133
Multiples of 3 number 166 and of 15 number 33, so 166 - 33 = 133.
More Coding Interview Problems questions
- Problem: How many non-negative integer pairs (x, y) satisfy 2x + 3y = 12? Run the code. python print(sum(1 for x in range(0, 7) for y in…
- Problem: Which algorithm solves the minimum-cost perfect assignment problem (bipartite, n x n cost matrix) in O(n^3) time?
- Problem: What is the complexity of Dinic's algorithm on a unit-capacity bipartite matching graph with V vertices and E edges?
- Problem: In Bellman-Ford, which statement about early termination is correct?
- Problem: What is the time complexity of Prim's algorithm on a graph stored as an adjacency matrix with V vertices?
- Problem: By the Sprague-Grundy theorem, what is the Grundy value of a sum of independent impartial games?