n - size of the array mode - to switch from top / bottom treversal it - iterator count - increases until it reaches n and then decreases lower - to ensure we move to the next row when columns go out of bounds
let n = arr . length , mode = 0 , it = 0 , lower = 0 ;