Your Dashboard
Interview Coaching
Learn
System Design
ML System Design
Code
Behavioral
Salary Negotiation
Interview Guides
Search
⌘K
Get Premium
Leetcode 2551. Put Marbles in Bags
Partition the array into k contiguous nonempty subarrays where each bag's cost is the sum of its endpoint weights, so the total score equals weights[0]+weights[n-1] plus the sum of the k-1 adjacent pair sums at cut positions. The problem reduces to choosing k-1 cuts (from n-1 adjacent-pair sums) to maximize or minimize their sum, so the answer is the difference between the sum of the largest k-1 and the smallest k-1 adjacent pair sums.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
All Regions
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.