Data Structures & AlgorithmsModerateTCS NQT Digital · CAT
Problem: The sum of the numbers in the sequence 1, 1+2, 1+2+3, …, up to 1+2+…+12 is what value?
- A. 78
- B. 286
- C. 650
- D. 364
Correct answer: D. 364
Σ T(k) for k = 1..12 is the tetrahedral number 12 · 13 · 14 / 6 = 364. 78 is the last term T(12), 286 stops at 11, and 650 sums the squares instead.
More Coding Interview Problems questions
- Problem: In the array [2, 4, 6, 8, 10], count the number of subarrays whose sum is divisible by 4.
- Problem: A stack-based bracket checker reads the string "([]{()})[" and reports the number of unmatched opening brackets at the end (0 if…
- Problem: An LRU cache of capacity 2 handles requests 1, 2, 1, 3, 2, 1, 4. Each request that is not cached causes a miss and evicts the…
- Problem: Find the number of integer pairs (a, b) with 1 ≤ a ≤ b ≤ 12 such that a and b have the same remainder when divided by 4.
- Problem: Consider the directed graph with arcs 1→2, 2→3, 3→1, 3→4, 4→2, 4→5. How many vertices can reach vertex 5?
- Problem: A string of length 6 is formed using letters only from {a, b}, containing no substring "aa" or "bb". How many such strings are…