30 - Rod Cutting - Final DP solution in Java

@Rishi Srivastava Pseudo code: int[] dp = new int[n 1]; for (int i = 1; i is less than or equal to n; i ) { int maxVal = -1; for (int j = 0; j is less than i; j ) { maxVal = MAX(maxVal, price[j] dp[i - j - 1]); } dp[i] = maxVal; } return dp[n]; Time complexity = O(n^2) Space complexity = O(n) Github: Coding Ninjas:
Back to Top