fnplus / interview-techdev-guide

This repository contains curated technical interview questions by fn+geeks community
http://bit.ly/fnplusnow
MIT License
317 stars 325 forks source link

Create Rod_Cutting_Problem.java #681

Closed Purvesh77 closed 1 year ago

Purvesh77 commented 1 year ago

We can get the best price by making a cut at different positions and comparing the values obtained after a cut. We can recursively call the same function for a piece obtained after a cut. Let cutRod(n) be the required (best possible price) value for a rod of length n. cutRod(n) can be written as follows. cutRod(n) = max(price[i] + cutRod(n-i-1)) for all i in {0, 1 .. n-1}