Subset Sum to target dp problem

bottom up approach is giving tle in 2 cases while top down is working perfectly . so how to decide to use which approach ?

hello @mandeepchohan96

r u sure u r getting tle ?
pls share the screenshot of ur submission.
in my knowledge both approaches should work

@mandeepchohan96
u r getting run error.
becuase it space complexity is O(n*sum) which is too much
image

ur top down is working because u r using map for memoisation ,if u would have used array then u would have faced same error in that as well

yes sir its RUN error. and how to declare unordered_map for bottom up approach ?

i modify the code little bit…it now giving TLE.

@mandeepchohan96
try to do it in O(sum) space complexity

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.