Help with error

code: https://ide.codingblocks.com/s/428574

prob: https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ffc7/00000000001d3f56#problem

I found this problem similar to knapsack problem, so I used that approach but getting answer zero

hello @raghav007

here in this problem u need to buy maximum number of houses(u dont have profit or anything else) .
so the idea is very simple sort prices in ascending order.
and then simply start picking houses from left to right(ie cheapest to expensive) till ur picked sum <=B

oh okay but can you please tell why my solution is giving the answer as 0

image

here it should a[i]<=b .

ur solution is correct, but its time complexity is high.

use above stated approach to pass all the test cases

I applied memoization but something is wrong,

time n space complexity is still an issue .

O(t* n *b) here n and b csn be upto 10^5.

oh okay thanks, my master c++ course is almost over now and I think I have done it pretty decently is it realistic to get an internship in a good company by this summer if I start learning dev now?

yeah but dont leave dsa , practice questions regulary.

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.