Given a rod of length n(size of array) inches and an array price[] . price[i] denotes the value of a piece of length i. The task is to determine the maximum value obtainable by cutting up the rod and selling the pieces.
Example 1
Input: price[] = [3, 5, 8, 9, 10, 17, 17, 20]
Output: 24
Explanation: The maximum obtainable value is 24 by cutting the rod into 8 pieces of length 1, i.e, 8*price[1]= 8*3 = 24.
Example 2
Input: price[] = [1, 10, 3, 1, 3, 1, 5, 9]
Output: 40
Explanation: The maximum obtainable value is 40 by cutting the rod into 4 pieces of length 2, i.e, 4*price[2]= 4*10 = 40
Sign in to write, run, and submit your solution against the full test suite.