Calculate the number of operations needed to make 1 st k elements equal to the kth element i . e . the 1 st window
int opsNeeded = 0 ; for ( int i = 0 ; i < k ; i ++ ) { opsNeeded += ar [ k - 1 ] - ar [ i ] ; }