Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Top Down Rod Cutting DP Example in Swift (Inefficient Version)
func maxProfitRodCut(prices: [Int], length: Int) -> Int {
if length <= 0 {
return 0
var currentMax = Int.min
for index in (1...length) {
currentMax = max(currentMax, prices[index - 1] + maxProfitRodCut(prices: prices, length: length - index))
return currentMax
maxProfitRodCut(prices: [1,6,3,6], length: 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment