heyy, on submission two tc shows tle . when i increase the size of my dp array to 10000007 it shows error but works fine with 100000. Please check why?
Time limit exceeded on two test cases
it was giving correct ans for the given example and few others which i tested but on increasing this value compilation error came
in the question constraint for the sum is given as 10000007. hence its necessary to increase the size of dp right? I took less size earlier thats why it showed tle?
@Aparna agar bda size to loge to error islie throw krrha hai kyunki hm itna bda size of 2d array nhi le skte,can you please send question link I will submit it and do correction.
Given a set of βnβ non-negative integers, and a value βsumβ, determine if there is a subset of the given set with sum equal to given sum. Input Format 1st Line: n sum 2nd Line: a1 a2β¦β¦an (Array Values) Constraints 1<= n <= 5000 1<= sum <= 10^7 1<= Ai <=10^5 Output Format Yes, if sum exist No, it sum does not exist Sample Input 5 10 1 2 3 4 5
@Aparna hey ap apne code ko space optimise kro as 2d dp will take more space therefore it is giving error.You can use 2 d matrix with 2 rows only and update row each time from the previous row and update previous ,here is code for reference:
can you give me the top-down approach to this solution
@Aparna hey is approach me khali bottom up hi kam krega ap ek kam kr skte ho ki aap recursion with memoisation me jo apki approach thi that is top down me ap usme map le skte hai instead of 2 d array and jo index the na 2 d array me unke combination se key bna lo map ki aur uski jgah pr value lelo dp ki.Ye try kro pls.
iska jo recursive approach hoga normal uski complexity kitni hogi?