Data Structures & AlgorithmsHardTCS NQT · Accenture
Problem: A matrix of size 4×4 is filled row-wise with 1 to 16 (row 0 holds 1–4, row 1 holds 5–8, and so on). It is rotated 90 degrees clockwise. After rotation, what value is at row 1, column 2 (0-indexed)?
- A. 6
- B. 11
- C. 10
- D. 7
Correct answer: A. 6
A clockwise rotation maps new[i][j] = old[n − 1 − j][i], so new[1][2] = old[1][1] = 6. Rotating counter-clockwise gives old[2][2] = 11, transposing without reversing gives old[2][1] = 10, and reading the unrotated matrix gives 7.
More Coding Interview Problems questions
- Problem: In the string "racecarbanana", find the number of distinct palindromic substrings of length at least 3.
- Problem: On a line of 12 cells (1–12), a robot starts at cell 1. Each second it moves to the cell i+3 if that cell is still ≤ 12 and not…
- Problem: A string is built by writing the first 15 positive integers in binary, concatenated in order (1, 10, 11, 100, ..., 1111). How…
- Problem: A sorted array [1, 3, 3, 5, 8, 8, 8, 13, 21] is searched for the value 8 using the standard lower-bound binary search (find the…
- Problem: A tree has 7 nodes 1–7 with edges 1-2, 1-3, 2-4, 2-5, 3-6, 6-7. Each node is coloured red if its depth from node 1 is even and…
- Problem: Starting with the sorted list 1, 4, 9, 16, 25, 36, two operations alternate: first remove the largest element, then append the…