Tap here to switch tabs
Problem
Submissions

Problem: Minimum Total Operations

med
30 min
Try to solve the Minimum Total Operations problem.

Statement

You are given an integer array nums.

In one operation, you can select any prefix of nums and an integer xx, then add xx to every element in that prefix.

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

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Total Operations

med
30 min
Try to solve the Minimum Total Operations problem.

Statement

You are given an integer array nums.

In one operation, you can select any prefix of nums and an integer xx, then add xx to every element in that prefix.

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

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9