Tap here to switch tabs
Problem
Submissions

Problem: Find Minimum Cost to Remove Array Elements

Find Minimum Cost to Remove Array Elements asks you to repeatedly remove two of the first three values, paying their maximum, then remove the final one or two together at their maximum; return minimum total cost.

Statement

You are given an integer array nums.

In each operation, you remove elements from nums based on the following rules:

  • If nums.length is at least 33, select any 22 elements from the first 33 elements of nums and remove them. The cost of this operation is the maximum of the 22 chosen elements.

  • If nums.length is less than 33, remove all remaining elements from nums. The cost of this operation is the maximum of all the removed elements.

Return the minimum total cost to remove all elements from nums.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq nums[i] ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find Minimum Cost to Remove Array Elements

Find Minimum Cost to Remove Array Elements asks you to repeatedly remove two of the first three values, paying their maximum, then remove the final one or two together at their maximum; return minimum total cost.

Statement

You are given an integer array nums.

In each operation, you remove elements from nums based on the following rules:

  • If nums.length is at least 33, select any 22 elements from the first 33 elements of nums and remove them. The cost of this operation is the maximum of the 22 chosen elements.

  • If nums.length is less than 33, remove all remaining elements from nums. The cost of this operation is the maximum of all the removed elements.

Return the minimum total cost to remove all elements from nums.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq nums[i] ≤106\leq 10^6