Data Structures & AlgorithmsModerateTCS NQT · SSC CGL Tier 2
Problem: The sum of the squares of the odd numbers from 1 to 19 is what value?
- A. 1330
- B. 2470
- C. 1540
- D. 100
Correct answer: A. 1330
n(2n − 1)(2n + 1)/3 with n = 10 gives 10 · 19 · 21 / 3 = 1330. All squares 1..19 give 2470, the even squares up to 20² give 1540, and 100 is the sum of the odd numbers themselves.
More Coding Interview Problems questions
- Problem: A grid of 3 rows and 3 columns is filled with the numbers 1 to 9 row by row. A "line" is a complete row, column or main diagonal…
- Problem: What is the number of lattice points (x, y) with x, y ≥ 0 and x + y ≤ 5?
- Problem: The array [5, 1, 4, 2, 3] is sorted by repeatedly swapping adjacent elements that are out of order (bubble sort). How many passes…
- Problem: The Hamming weight (number of 1-bits) of each integer from 0 to 15 is summed. What is the total?
- Problem: A set of letters {A, B, C, D, E} is arranged in a row. How many arrangements have A immediately to the left of B?
- Problem: The number of ways to split a line of 6 people into 2 groups of 3 (groups are distinguishable by their first member, so each…