Beats 100% java users || space complexity: O(1) || Runtime: 0ms
Intuition\n Describe your first thoughts on how to solve this problem. \nFlipping: Horizontally flipping an image means reversing each row in the 2D array. The 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFlipping: Horizontally flipping an image means reversing each row in the 2D array. The first element becomes the last, the second becomes the second last, and so on.\n\nInverting: Inverting an image means replacing each 0 with 1 and each 1 with 0. This can be done using a bitwise XOR operation with 1.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\na. Iterate through each row in the image matrix. For each row, you will perform both flipping and inverting.\n\nb. For each row, iterate up to the middle of the row (inclusive for odd lengths). This is done to swap the elements on either side of the row simultaneously.\n\nc. Flip and invert simultaneously:\n\n1. Use a temporary variable to store the inverted value of the current element (image[i][j] ^ 1).\n2. Assign the inverted value of the element on the opposite side (image[i][image[0].length - j - 1] ^ 1) to the current position.\n3. Assign the temporary variable\'s value to the opposite side.\n\nd. Return the modified image once all rows are processed.\n\n# Complexity\n- Time complexity: O(n * m);\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1);\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public int[][] flipAndInvertImage(int[][] image) {\n         for(int i = 0; i < image.length; i++){\n            for(int j = 0; j < (image[i].length +1)/2 ; j++){\n                //reversing the array and doing XOR 1 to get complement of flipped number.\n               int temp = image[i][j] ^ 1;\n               image[i][j] = image[i][image[0].length-j-1] ^ 1;\n               image[i][image[0].length-j-1] = temp;\n            }\n        }\n        return image;\n    }\n}\n```
['Java']