Back to course home
0% completed
Solution: Reduction Operations to Make the Array Elements Equal
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!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible