Problem · Matrix

Matrix Transformation

Learn this problem
EasyUberOA
See Uber hiring insights

Problem 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:

  1. First query is 0, so we rotate the matrix 90 degrees clockwise.
  2. Second query is 1, so we reflect the rotated matrix in its main diagonal.
  3. 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

drafts saved locally
public int[][] matrixTransformation(int[][] a, int[] q) {
  // write your code here
}
a[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
q[0, 1, 2]
expected[[3, 6, 9], [2, 5, 8], [1, 4, 7]]
checking account