Data Structures & AlgorithmsHardGATE CS · competitive programming
An n×n matrix is rotated 90° clockwise. The original is [[1,2,3],[4,5,6],[7,8,9]]. Which value is now in the top-left corner?
- A. 3
- B. 9
- C. 7
- D. 1
Correct answer: C. 7
A clockwise rotation sends (i, j) to (j, n−1−i), so the new top-left comes from the bottom-left corner, 7. A counter-clockwise rotation would give 3.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- A 4×5 matrix holds the value r·5 + c + 1 at row r and column c (0-based). Visited in spiral order from the top-left corner, what is the…
- The 3×4 matrix [[1,3,5,7],[10,11,16,20],[23,30,34,60]] is treated as one sorted array of 12 entries, with mid = (lo + hi) / 2, row = mid /…
- What is the minimum number of swaps needed to transpose a 6×6 matrix in place?
- For (i = 1; i < n; i = 2) and, inside it, (j = 0; j < i; j++), with n = 1024, how many times does the inner body run in total?
- How many times does the body of for (i = 2; i i ≤ n; i++) run for n = 10⁶?
- For (i = 1; i ≤ n; i = 3) with n = 1000, how many times does the body run?