Back to course home
0% completed
Vote For New Content
Reduction Operations to Make the Array Elements Equal (medium)
Problem Statement
Given an array of integers nums
, return the number of operations required to make all elements in nums
equal. To perform one operation, you can follow the below steps:
- Select the
maximum
element ofnums
. If there are multiple occurrences of the maximum element, choose the element which has lowest indexi
. - Select the
second largest
element ofnums
. - Replace the element at index
i
with the second largest element.
Examples
Example 1:
- Input:
[3, 5, 5, 2]
- Expected output:
5
- Justification:
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page