Tap here to switch tabs
Problem
Submissions

Problem: Reduction Operations to Make the Array Elements Equal

Reduction Operations to Make the Array Elements Equal asks you to repeatedly lower one maximum array value to the next distinct lower value and return the operations needed for all values to match.

Statement

You are given an integer array nums. Your objective is to make all elements in nums equal by repeatedly applying a reduction operation.

In a single operation, perform the following sequence of actions:

  • Find the maximum value in nums at index i. If multiple elements share the maximum value, choose any such index.

  • Find the largest value in nums that is strictly smaller than the maximum value.

  • Reduce nums[i] to this next largest value.

Return the total number of operations required to make all elements in nums equal.

Constraints:

  • 1≤1 \leq nums.length ≤5×104\leq 5 \times 10^4

  • 1≤1 \leq nums[i] ≤5×104\leq 5 \times 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Reduction Operations to Make the Array Elements Equal

Reduction Operations to Make the Array Elements Equal asks you to repeatedly lower one maximum array value to the next distinct lower value and return the operations needed for all values to match.

Statement

You are given an integer array nums. Your objective is to make all elements in nums equal by repeatedly applying a reduction operation.

In a single operation, perform the following sequence of actions:

  • Find the maximum value in nums at index i. If multiple elements share the maximum value, choose any such index.

  • Find the largest value in nums that is strictly smaller than the maximum value.

  • Reduce nums[i] to this next largest value.

Return the total number of operations required to make all elements in nums equal.

Constraints:

  • 1≤1 \leq nums.length ≤5×104\leq 5 \times 10^4

  • 1≤1 \leq nums[i] ≤5×104\leq 5 \times 10^4