1887. Reduction Operations to Make the Array Elements Equal
https://leetcode.com/problems/reduction-operations-to-make-the-array-elements-equal
Description
Given an integer array nums
, your goal is to make all elements in nums
equal. To complete one operation, follow these steps:
Find the largest value in
nums
. Let its index bei
(0-indexed) and its value belargest
. If there are multiple elements with the largest value, pick the smallesti
.Find the next largest value in
nums
strictly smaller thanlargest
. Let its value benextLargest
.Reduce
nums[i]
tonextLargest
.
Return the number of operations to make all elements in nums
equal.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= nums.length <= 5 * 104
1 <= nums[i] <= 5 * 104
ac
Previous1886. Determine Whether Matrix Can Be Obtained By RotationNext1888. Minimum Number of Flips to Make the Binary String Alternating
Last updated