Given an n×n binary matrix image, flip each row horizontally and invert it. To flip: reverse each row. To invert: replace 0→1, 1→0 (XOR with 1).
image = [[1,1,0],[1,0,1],[0,0,0]][[1,0,0],[0,1,0],[1,1,1]]The trick: flip (reverse) + invert (XOR 1) can be fused. For endpoints L and R:
• L ≠ R values: temp=L^1, L=R^1, R=temp. Since L and R are opposite bits, swapping+inverting each gives back the original values — net zero change.
• L = R values: same as above but now L^1 ≠ L, so both actually change — both get XOR'd.
• L = R (middle): same cell written twice — final result is XOR 1 (invert).