changed here as in case of even elements there will be 2 medians
let median2 = arr [ ( ( n * m ) / 2 ) - 1 ] ; let minOperations2 = 0 ; for ( let i = 0 ; i < n * m ; ++ i ) minOperations2 += Math . abs ( arr [ i ] - median2 ) / k ; minOperations = Math . min ( minOperations , minOperations2 ) ; }