Problem · Matrix
Matrix Transformation
Learn this problemProblem statement
Imagine you have a square matrix of numbers, and you're given a set of instructions, called queries, to transform this matrix in different ways. Depending on the query, you might rotate the matrix 90 degrees clockwise, reflect it along its main diagonal, or reflect it along its secondary diagonal. Your task is to apply all these transformations in the order given and return the matrix after it's been beautifully transformed by each of the queries. Don't worry about finding the most efficient way to do this; just ensure your approach isn't too slow for the given task.
Function
matrixTransformation(a: int[][], q: int[]) → int[][]Examples
Example 1
a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]q = [0, 1, 2]return = [[3, 6, 9], [2, 5, 8], [1, 4, 7]]An explanation based on educated guess. Might be right might be wrong tho..
After processing the queries on matrix a:
- First query is
0, so we rotate the matrix 90 degrees clockwise. - Second query is
1, so we reflect the rotated matrix in its main diagonal. - Third query is
2, so we reflect the matrix in its secondary diagonal.
The final matrix after all transformations is [[3, 6, 9], [2, 5, 8], [1, 4, 7]].
Constraints
🍍🍍More Uber problems
- Last Truck to Leave the LaneOA · Seen Jul 2026
- Chain of CommandOA · Seen Jul 2026
- Jump Game with Prime-3 StepsOA · Seen Jun 2026
- Total Palindrome Substring CostOA · Seen Jun 2026
- Earliest Time All Users Are ConnectedPHONE SCREEN · Seen May 2026
- Tournament Rounds by RankPHONE SCREEN · Seen May 2026
- Farthest Seat AssignmentONSITE INTERVIEW · Seen May 2026
- Convex Function MinimizationPHONE SCREEN · Seen May 2026