Data Structures & AlgorithmsModerateTCS NQT · basics
Problem: What is the sum of the squares of the odd numbers from 1 to 10? Run the code.
Problem: What is the sum of the squares of the odd numbers from 1 to 10? Run the code.
print(sum(x * x for x in range(1, 11) if x % 2 == 1))What is printed?
- A. 130
- B. 175
- C. 165
- D. 385
Correct answer: C. 165
1 + 9 + 25 + 49 + 81 = 165. Summing all squares 1 to 10 gives 385, which is the trap.
More Coding Interview Problems questions
- Problem: How many iterations does Euclid's algorithm take for gcd(1071, 462)? Count the loop passes of the code. python a, b = 1071, 462…
- Problem: From the left, how many buildings of heights [3, 1, 4, 2, 5] are visible (a building is visible if it is strictly taller than all…
- Problem: For the sorted array [1, 2, 2, 2, 5, 7], how many values are at most 2? Run the code. python import bisect a = [1, 2, 2, 2, 5, 7]…
- Problem: How many strings of length 3 over the alphabet {a, b, c} have no two equal adjacent characters? Run the code. python from…
- Problem: How many divisors does 720 have? Run the code. python print(sum(1 for d in range(1, 721) if 720 % d == 0)) What is printed?
- Problem: How many ways are there to decode the digit string '111' (1 maps to A, ..., 26 maps to Z)? Run the DP. python s = '111' dp = [1]…