Data Structures & AlgorithmsModerateSSC CGL Tier 2 · TCS NQT
Problem: What is the sum of the first 50 odd positive integers (1 + 3 + 5 + … + 99)?
- A. 4950
- B. 2401
- C. 2500
- D. 2550
Correct answer: C. 2500
The sum of the first n odd numbers is n², so 50² = 2500. Summing all of 1..99 gives 4950, using n = 49 gives 2401, and summing the first 50 even numbers gives 2550.
More Coding Interview Problems questions
- Problem: In a binary-tree-free DFS on the undirected graph with edges 0-1, 0-2, 1-3, 2-4, 3-4, 4-5, starting from vertex 0 and always…
- Problem: What does the following print? python print(sorted(['b', 'B', 'a', 'A']))
- Problem: Selection sort is run on [4, 3, 2, 1] in the usual way (for each position, find the minimum of the unsorted suffix and swap it…
- Problem: A Rule 90 cellular automaton on an infinite line starts with a single live cell. A cell's next state is 1 exactly when its two…
- Problem: A lucky 4-digit ticket has the sum of its first two digits equal to the sum of its last two digits. Each ticket number runs from…
- Problem: A grid of 5×5 cells has 'X' blocked cells at (0,2), (1,2), (2,2), (3,2) (row, column, 0-indexed); the rest are open. Cells…