Data Structures & AlgorithmsVery hardTCS NQT Digital · Product Company SDE
Problem: In a spiral traversal of a 5×5 matrix filled row-wise with 1 to 25, the traversal starts at the top-left and goes right, then down, then left, then up, shrinking the boundary each time. What is the sum of the first 13 values visited?
- A. 175
- B. 191
- C. 199
- D. 91
Correct answer: A. 175
The spiral visits 1-5, then 10, 15, 20, 25, then 24, 23, 22, 21: these 13 values sum to 175. Taking 14 values adds 16 (191), going down first (counter-clockwise) gives 199, and reading the first 13 values row-wise gives 91.
More Coding Interview Problems questions
- Problem: A bitmask DP problem: count the subsets of {1, 2, ..., 10} whose sum is a multiple of 5 (the empty set counts, since its sum 0 is…
- Problem: An 8-bit unsigned counter starts at 250 and is incremented by 7 each step, wrapping modulo 256. How many increments until the…
- Problem: The Pascal triangle rows are numbered from row 0 (single 1). What is the sum of all entries in row 12 that are odd?
- Problem: Count the strings of length 4 over the alphabet {a, b, c} that contain no two adjacent equal characters and do not contain the…
- Problem: The number of inversions in a permutation of 1..8 given as [4, 7, 1, 8, 2, 6, 3, 5] is what value?
- Problem: On a tree with 9 nodes labelled 1–9, edges 1-2, 1-3, 2-4, 2-5, 3-6, 6-7, 6-8, 8-9, count the unordered pairs of nodes whose path…