Myvideo

Guest

Login

30 - Rod Cutting - Final DP solution in Java

Uploaded By: Myvideo
1 view
0
0 votes
0

@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:

Share with your friends

Link:

Embed:

Video Size:

Custom size:

x

Add to Playlist:

Favorites
My Playlist
Watch Later