Tap here to switch tabs
Problem
Submissions

Problem: Reduction Operations to Make the Array Elements Equal

med
30 min
Try to solve the Reduction Operations to Make the Array Elements Equal problem.

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 ≤5imes104\leq 5 imes 10^4

  • 1≤1 \leq nums[i] ≤5imes104\leq 5 imes 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Reduction Operations to Make the Array Elements Equal

med
30 min
Try to solve the Reduction Operations to Make the Array Elements Equal problem.

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 ≤5imes104\leq 5 imes 10^4

  • 1≤1 \leq nums[i] ≤5imes104\leq 5 imes 10^4