Flipping an Image | Easy C solution
IntuitionApproachThe approach uses a two-pointer technique to flip and invert each row of the binary image in-place. The left and right pointers start at the be
# Intuition
![Screenshot 2025-02-05 112056.png](https://assets.leetcode.com/users/images/7c60af0c-3faf-4feb-b9bd-240a35e55c7b_1738734667.674509.png)
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->
The approach uses a two-pointer technique to flip and invert each row of the binary image in-place. The left and right pointers start at the beginning and end of each row, respectively, and swap elements while inverting them (0 → 1 and 1 → 0). If the row length is odd, the middle element is inverted separately. This ensures both operations—flipping and inverting—are performed in a single pass per row, resulting in an O(M × N) time complexity with O(1) extra space since modifications are done directly on the input matrix.
# Complexity
- Time complexity: O(M × N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```c []
/**
 * Return an array of arrays of size *returnSize.
 * The sizes of the arrays are returned as *returnColumnSizes array.
 * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
 */
int** flipAndInvertImage(int** image, int imageSize, int* imageColSize, int* returnSize, int** returnColumnSizes) {
    *returnSize=imageSize;
    *returnColumnSizes = imageColSize;
    for(int i=0;i<imageSize;i++){   // for traversing
        int right=0;               // starts from leftmost elemnet
        int left=*imageColSize-1;   // starts from rightmost element
        while(right<=left){
            if(right==left){        //if right and left pointers are equal then
                image[i][right]=1-image[i][left];
                break;
            }
            int temp=image[i][right];       // set the value of tem to right var
            image[i][right]=!image[i][left];    // set the inverted value of right to left ele
            image[i][left] = !temp;
            right++;
            left--;
        }
    }
    return image;
}
```
['C']