#3469
Find Minimum Cost to Remove Array Elements
expert · 1185 · lc medium +32 · 21.4% accepted · 148 likes · top 2%
Description
Clear the integer array nums at minimum cost. At each step:
- If at least three elements remain, pick any two of the first three and remove them; the cost equals the larger of the two removed values.
- If fewer than three elements remain, remove them all in one step at a cost equal to their maximum.
Return the minimum total cost to empty the array.
Code
1
2
3