Minimum Cost to Cut a Roll of Packing Film at Marked Points

Last updated: November 29, 2026

Quick Overview

A roll of packing film of a given length must be cut at a set of marked positions, in any order; each cut costs the current length of the piece being cut. Return the minimum total cost.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


A roll of packing film of a given length must be cut at a set of marked positions, in any order; each cut costs the current length of the piece being cut. Return the minimum total cost.

An interval DP framed around packaging operations in Amazon fulfillment centers. The interviewer looks for defining intervals over cut points rather than every unit of length, and for an explanation of why the cut order changes total cost.

What the Interviewer Expects
  • Sort cuts and add the ends 0 and length
  • Define dp[i][j] over consecutive cut points
  • Cost of the first cut inside (i, j) is pts[j] - pts[i]
  • Fill by increasing gap
  • O(k^3) in the number of cuts, independent of length
Key Topics to Cover
interval dynamic programming
optimal order
sorting
matrix chain pattern
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Why is indexing by cut points better than by length?
  • How would you output the cut order?
  • Is there a Knuth-style optimization that brings this to O(k^2)?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: integer length and list marks of distinct cut positions strictly inside the roll. Output: minimum total cost....

High-Level Design

Sort marks and form pts = [0] + marks + [length]. Consider the piece between pts[i] and pts[j] that still needs all cuts strictly between them. Whatever cut k is made first on that piece costs t...


Submit Your Answer
Markdown supported