Practice Minimum Cost to Merge Stones
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
There are n piles of stones arranged in a row. The ith pile has stones[i] stones. A move consists of merging exactly k consecutive piles into one pile, and the cost of this move is equal to the total number of stones in these k piles. Return the minimum cost to merge all piles of stones into one pile. If it is impossible, return -1.
Source: Minimum Cost to Merge Stones on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
stones = [3,2,4,1], k = 2
20
# Example 2
stones = [3,2,4,1], k = 3
-1
# Example 3
stones = [3,5,1,2,6], k = 3
25
Constraints
Related LeetCode Problems
Practice more problems similar to Minimum Cost to Merge Stones.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.