Problem · Matrix
Transform Binary Matrix
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
rotationdegrees.rotationis one of90,180, or270.
- 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.
Examples
01 · Example 1
n = 3 rotation = 270 vertical_flip = 0 horizontal_flip = 1 image = [[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
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