Score After Flipping Matrix

`class Solution:    def matrixScore(self, grid: List[List[int]]) -> int:        col_size=len(grid[0])        row_size=len(grid)        mask=(1<<col_size)-1        for i in range(row_size):            val=0            for j in grid[i]:                val<<=1                val|=j            if(val^mask>val):                val1=val^mask                cnt=1                while(val1):                    bit = val1&1                    grid[i][col_size-cnt]=bit                    cnt+=1                    val1>>=1                for j in range(col_size):            count_zero=0            count_one=0            for k in range(row_size):                if(grid[k][j]==0):                    count_zero+=1                else:                    count_one+=1            if(count_zero>count_one):                print(count_zero,"j",j)                for i in range(row_size):                    if (grid[i][j]==0):                        grid[i][j]=1                      else:                        grid[i][j]=0        sum_=0        for i in grid:            cnt=1            for j in i:                sum_+=(2**(col_size-cnt))*j                cnt+=1        return sum_            `

--

--

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.

Love podcasts or audiobooks? Learn on the go with our new app.

Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.