diff --git a/knapsack/knapsack.py b/knapsack/knapsack.py index 18a36c3bcdda..941e9c814d16 100644 --- a/knapsack/knapsack.py +++ b/knapsack/knapsack.py @@ -20,6 +20,10 @@ def knapsack(capacity: int, weights: list[int], values: list[int], counter: int) which is the limit of the capacity. """ + # Invalid Case + if len(values)!=len(weights): + return -1 + # Base Case if counter == 0 or capacity == 0: return 0