Practice Minimum Operations to Make Array Values Equal to K
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
An integer h is valid for the current nums when all values strictly greater than h are identical. In one operation, choose such an h and replace every value greater than h with h, leaving all other values unchanged. Return the fewest operations needed to make every element equal to k, or -1 if impossible.
Source: Minimum Operations to Make Array Values Equal to K on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [5,2,5,4,5], k = 2
2
# Example 2
nums = [2,1,2], k = 2
-1
# Example 3
nums = [9,7,5,3], k = 1
4
Constraints
Related LeetCode Problems
Practice more problems similar to Minimum Operations to Make Array Values Equal to K.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.