Why is this wrong?


whats prob in this

Hello @pranjalarora98
check now ->

Oh small silly mistake and why 2 run errors?

run errors in 2 cases

becuase of memory limit.
ur solution space complexity is O(n*k).
check now (declared ur dp array as global)->

another space optimised approach is there do check that as well

But why do we need to declare globally? its not working with long long int also
Whatever number user enters that much i am making so it shud work right?

Even when we make global only that much will be utilised rest will be 0

u need to reduce space , so dont use long long boolean is fine.

in function scope memory get allocated on stack whereas in global scope memory is allocated on data segmente .
the later has higher memory capacity than the former one thats why i said to declare it global.

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.