Back to course home
0% completed
Vote For New Content
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
maximumelement ofnums. If there are multiple occurrences of the maximum element, choose the element which has lowest indexi. - Select the
second largestelement ofnums. - Replace the element at index
iwith the second largest element.
Examples
Example 1:
- Input:
[3, 5, 5, 2] - Expected output:
5 - Justification:
.....
.....
.....
Like the course? Get enrolled and start learning!