From b61911802f79b9edba6f4ea67985a8b53f3d6ce3 Mon Sep 17 00:00:00 2001 From: abhijitgawai Date: Sun, 3 Oct 2021 15:45:05 +0530 Subject: [PATCH] There is an invalid case also in Knapsack --- knapsack/knapsack.py | 4 ++++ 1 file changed, 4 insertions(+) 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