Getting TLE in test cases

im getting TLE in 2/4 test cases https://ide.codingblocks.com/s/285997

hello @Ishitagambhir
u r trying to generate all possible subset .
and total 2^n subset is possible where value of n can be upto 1000.
because of this exponential time complexity u r getting tle.

try to optimise it by memoising ur result.

how to use memoisation here?

this should be ur dp state-> dp[index][currentsum]

first initialise ur dp array with -1 , to indicate unvisited state.

in u recursive function call if(dp[index][currentsum]!-1) That means it is already visited so simply return dp[index][currentsum]

otherwise solve the current state by making call to subproblem.
and whathever value it returns, store it in ur dp array for furthur uses.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.