Minimum number of operations required to make a permutation of first N natural numbers equal | Function to find the minimum number of operations required to make all array elements equal ; Store the count of operations required ; Increment by K - 1 , as the last element will be used again for the next K consecutive elements ; Increment count by 1 ; Return the result ; Given Input
function MinimumOperations ( A , N , K ) { let Count = 0 ; let i = 0 ; while ( i < N - 1 ) { i = i + K - 1 ; Count ++ ; } return Count ; } let A = [ 5 , 4 , 3 , 1 , 2 ] ; let K = 3 ; let N = A . length ; document . write ( MinimumOperations ( A , N , K ) ) ;