Sir doubt in this question

why is this code failing test cases

??

Hey @tejasddongare
I am looking into ur code , have some patience :slight_smile:

If you read the problem statement carefully then you will realise that the N value given in input does not represent the size of the array. Infact it is quite useless.
This is a 1D DP problem. The size of the array is W only , not N.

sir but in hint video it is said that this is 0/1 knapsack problem

0/1 knapsack can also be reduced to 1d DP

Refer to this for correct approach : Here’s the full code - https://ide.codingblocks.com/s/344731

sir but if i try to implement like knapsack then whats wrong in my code??? why is my code failing test cases??

Size of the array is W which u are inputtng
So re read the question line by line

hello @tejasddongare i have modified your code completely .


if you don’t understand anything please ask here i will answer .
Happy Learning !!

but sir even after replacing now array with weight its failing 2 test cases why???

tushar sir thanks alot

@tejasddongare happy to help you .