Maintain two arrays , one for rows operation and one for column operation
let row = new Array ( n ) ; row . fill ( 0 ) ; let col = new Array ( n ) ; col . fill ( 0 ) ; for ( let i = 0 ; i < size ; i ++ ) { let x = q [ i ] [ 0 ] ; let y = q [ i ] [ 1 ] ;