https://leetcode.com/problems/flipping-an-image

Let us do exactly what is asked in this problem: for each row: flip the image horizontally, then invert it. Quick way to get 0 from 1 and 1 from 0 is to use 1^q (however tests are so small, so difference is not very big).

Complexity: time complexity is O(mn), where m, n are sizes of image. Space complexity is also O(mn) if we count output and O(1) space if we do not count. Note, that if we allowed to modify original image, than we can have O(1) space.

class Solution:
    def flipAndInvertImage(self, A):
        return [[1^q for q in row[::-1]] for row in A]

If you like the solution, you can upvote it on leetcode discussion section: Problem 0832