Mid From PDF Coding C# Coding Interview

Rod Cutting Problem?

int RodCutting(int[] prices, int n)
{
int[] dp = new int[n + 1];
dp[0] = 0;

Follow on:

for (int i = 1; i <= n; i++)
{
int maxVal = int.MinValue;
for (int j = 0; j < i; j++)
{
maxVal = Math.Max(maxVal, prices[j] + dp[i - j - 1]);
}
dp[i] = maxVal;
}
return dp[n];
}

Explanation:

Max revenue by cutting rod into pieces of various lengths.

More from C# Programming Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details