We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e499d3b commit c6e01a8Copy full SHA for c6e01a8
src/main/java/com/thealgorithms/dynamicprogramming/RodCutting.java
@@ -22,6 +22,9 @@ public static int cutRod(int[] price, int n) {
22
if (price == null || price.length == 0) {
23
throw new IllegalArgumentException("Price array cannot be null or empty.");
24
}
25
+ if (n < 0) {
26
+ throw new IllegalArgumentException("Rod length cannot be negative.");
27
+ }
28
// Create an array to store the maximum obtainable values for each rod length.
29
int[] val = new int[n + 1];
30
val[0] = 0;
@@ -40,4 +43,4 @@ public static int cutRod(int[] price, int n) {
40
43
// The final element of 'val' contains the maximum obtainable value for a rod of length 'n'.
41
44
return val[n];
42
45
-}
46
+}
0 commit comments