Data Structures & AlgorithmsModerateProduct Company SDE · CP practice
Problem: What is the sum of all integers in [1, 200] that are both odd and multiples of 5? Run the code.
Problem: What is the sum of all integers in [1, 200] that are both odd and multiples of 5? Run the code.
print(sum(x for x in range(1, 201) if x % 2 == 1 and x % 5 == 0))What is printed?
- A. 4100
- B. 2000
- C. 2100
- D. 20
Correct answer: B. 2000
Odd multiples of 5 are 5, 15, …, 195: 20 terms averaging 100, total 2000. All multiples of 5 sum to 4100, the even ones (10..200) to 2100, and 20 is the count.
More Coding Interview Problems questions
- Problem: What is the maximum number of distinct characters in a substring of length 4 of 'abcabcabc'? Run the code. python s = 'abcabcabc'…
- Problem: How many ways are there to tile a 2 x 6 board with 2 x 1 dominoes? Run the DP. python f = [1, 1] for n in range(2, 7)…
- Problem: What is the minimum number of edges to remove from a 5-vertex complete graph to leave a spanning tree? Run the code (answer = E…
- Problem: How many integers from 1 to 10^6 have exactly one set bit (power of two)? Run the code. python print(sum(1 for x in range(1, 10 6…
- Problem: What is the maximum number of points on a line among (0,0), (1,1), (2,2), (3,5), (4,4) (collinear with the diagonal)? Run the…
- Problem: What is the time complexity of the Hopcroft-Karp algorithm for maximum matching on V vertices and E edges?