Skip to main content
All Questions

Split an array into K contiguous subarrays with minimum total cost.

Unlock detailed company stats for this questionUpgrade

Given an array and a required number of partitions, split the array into that many non-empty subarrays. The cost of each split is computed from the values at the split indices (start and end). Find the maximum and minimum possible total cost.

Example: array = [1, 3, 5, 10], numPartitions = 2. cost([1,3]) = 1+3 = 4, cost([5,10]) = 5+10 = 15, total cost = 19.

It was a greedy problem.

Also asked as · Split an array into k non-empty subarrays and find the minimum and maximum total cost.

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.