Rod Cutting

medium
Unit 12 · Dynamic Programming II0/3 to milestone

A rod of length n can be cut into integer pieces; prices[i] is the price of a piece of length i + 1. Return (best_revenue, pieces) where pieces is a list of piece lengths achieving it, sorted descending. If several cut plans tie, prefer the one whose first piece (in the DP reconstruction, trying lengths from longest to shortest) is longest.

#dynamic-programming#optimization2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Rod Cutting · TechGradify