Problem · Matrix

Transform Binary Matrix

Learn this problem
EasyVisa logoVisaOA

Problem statement

You are given an n x n binary matrix representing an image.

Your task is to transform the image by applying the following operations in order:

  • Rotate the image clockwise by rotation degrees.
    • rotation is one of 90, 180, or 270.
  • If vertical_flip = 1, flip the image vertically, top to bottom.
  • If horizontal_flip = 1, flip the image horizontally, left to right.

Return the final transformed binary matrix after all operations are applied.

Function

transformImage(n: int, rotation: int, vertical_flip: int, horizontal_flip: int, image: int[][]) → int[][]

Examples

Example 1

n = 3rotation = 270vertical_flip = 0horizontal_flip = 1image = [[1,0,0],[0,1,1],[0,0,1]]return = [[1,1,0],[0,1,0],[0,0,1]]

Original pixels:

[[1,0,0],
 [0,1,1],
 [0,0,1]]

Rotate the image by 270 degrees clockwise:

[[0,1,1],
 [0,1,0],
 [1,0,0]]

vertical_flip is 0, so the image is not flipped vertically.

Perform the horizontal flip:

[[1,1,0],
 [0,1,0],
 [0,0,1]]

Note: The screenshot did not show a separate output line. FastPrep calculated this matrix from the visible rotation and flip steps so you can practice with a complete example. 🐥

More Visa problems

drafts saved locally
public int[][] transformImage(int n, int rotation, int vertical_flip, int horizontal_flip, int[][] image) {
  // write your code here
}
n3
rotation270
vertical_flip0
horizontal_flip1
image[[1,0,0],[0,1,1],[0,0,1]]
expected[[1,1,0],[0,1,0],[0,0,1]]
checking account