Code not giving desired output

code- https://ide.codingblocks.com/s/242544

hello @anubhavb11
you are not adding ur tempans to ans.
add that statement in ur.

i was debuging the code see in tempans all the ans are zero so no point of adding in ans

image
here ur indexing is not correct, it should l and r.

i corrected it still so many test case not passing

now check the constraints , and increase ur array size accordingly



only one test case is passed more

share ur updated code with me ,using cb ide

code- https://ide.codingblocks.com/s/242579

image
here it should be >=


still tle in 3 cases

for that u need to optimise ur approach.

ok
any hint you can give me?

but i have not studied dp yet

read approach 4.
two pointers

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.