class Solution: def oddCells(self, n, m, indices): # Initialise the matrix matrix = [] for x in range(n): new_row = [] for y in range(m): new_row.append(0) matrix.append(new_row) # Now apply steps for i in indices: ri = i[0] ci = i[1] for n in range(len(matrix[ri])): matrix[ri][n] += 1 for n in range(len(matrix)): matrix[n][ci] += 1 # now count odd values (this could be done while changes are made, but this is easier to reason) count = 0 for x in range(len(matrix)): for y in range(len(matrix[x])): if matrix[x][y] % 2 != 0: count += 1 return count s = Solution() print("Expected: 6") print("Got:", s.oddCells(2, 3, [[0, 1], [1, 1]]))