Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Convert All Elements to Zero

Try to solve the Minimum Operations to Convert All Elements to Zero problem.

Statement

You are given an array of integers nums of size n containing nonnegative integers.

In one operation, you can perform the following actions:

  1. Select a contiguous subarray nums[l..r] and an integer x>0x > 0 such that every element in the subarray satisfies nums[i] ≥x\geq x for all l≤i≤rl \leq i \leq r.

  2. Set nums[i] to 00 for all indices ii in the range [l,r][l, r] where nums[i] == x.

Return the minimum number of operations required to convert all elements in nums to 00.

Constraints:

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

  • 0≤0 \leq nums[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Convert All Elements to Zero

Try to solve the Minimum Operations to Convert All Elements to Zero problem.

Statement

You are given an array of integers nums of size n containing nonnegative integers.

In one operation, you can perform the following actions:

  1. Select a contiguous subarray nums[l..r] and an integer x>0x > 0 such that every element in the subarray satisfies nums[i] ≥x\geq x for all l≤i≤rl \leq i \leq r.

  2. Set nums[i] to 00 for all indices ii in the range [l,r][l, r] where nums[i] == x.

Return the minimum number of operations required to convert all elements in nums to 00.

Constraints:

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

  • 0≤0 \leq nums[i] ≤105\leq 10^5