Flipping an Image
Understand how to flip and invert an image represented by a binary matrix using horizontal flipping and inversion techniques. Explore bitwise manipulation methods to implement this function efficiently, strengthening problem solving skills for coding interviews.
We'll cover the following...
Statement
Given that an image is represented by an matrix containing s and s, flip and invert the image, and return the resultant image.
Horizontally flipping an image means that the mirror image of the matrix should be returned. Flipping horizontally results in .
Inverting an image means that every is replaced by , and every is replaced by . Inverting results in .
Constraints:
- Image should be a square matrix.
images[i][j]is either or .
Examples
Understand the problem
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Flipping an Image
Consider the following matrix as input. What is the output once it has been flipped and inverted?
Figure it out!
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Try it yourself
Implement your solution in the following coding playground.
export function flipAndInvertImage(image){// Replace this placeholder return statement with your codereturn [[]]}