Skip to main content
Back to problems
#1887
Medium Algorithms

Reduction operations to make the array elements equal

Array Sorting
72.5% acceptance
Feb 25, 2026
1273
51
Given an integer array nums, return the number of operations to make all elements in nums equal by repeatedly reducing the largest value to the next largest.

Solution

Rust
Time O(n log n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn reduction_operations(mut nums: Vec<i32>) -> i32 {
    nums.sort_unstable();
    let mut ops = 0i32;
    let mut levels = 0i32;
    for i in 1..nums.len() {
      if nums[i] > nums[i - 1] {
        levels += 1;
      }
      ops += levels;
    }
    ops
  }
}