3375. Minimum Operations to Make Array Values Equal to K
You are given an integer array
numsand an integerk.An integer
his called valid if all values in the array that are strictly greater thanhare identical.For example, if
nums = [10, 8, 10, 8], a valid integer ish = 9because allnums[i] > 9are equal to 10, but 5 is not a valid integer.You are allowed to perform the following operation on
nums:
- Select an integer
hthat is valid for the current values innums.- For each index
iwherenums[i] > h, setnums[i]toh.Return the minimum number of operations required to make every element in
numsequal tok. If it is impossible to make all elements equal tok, return -1.
1 | class Solution { |