Skip to content

Practice Find Minimum Cost to Remove Array Elements

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3469
LeetCode Problem

Find Minimum Cost to Remove Array Elements

Problem Statement

While nums has at least three elements, remove any two of its first three, paying the larger of the removed values. Once fewer than three elements remain, remove all of them in one operation, paying their maximum value. Return the minimum total cost to empty nums.

Source: Find Minimum Cost to Remove Array Elements on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [6,2,8,4]
Output
12

# Example 2

Input
nums = [2,1,3,3]
Output
5

Constraints

1 <= nums.length <= 1000
1 <= nums[i] <= 10^6

Related LeetCode Problems

Practice more problems similar to Find Minimum Cost to Remove Array Elements.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.