The complexity of my code is O(n) but still TLE is coming as an error

@gaganpreetsachdev1 don’t take cumulative sum, as it will not be O(n)


see the update.

your code isn’t o(n) as well

Your code is still giving TLE please check and revert

@gaganpreetsachdev1 it works fine
try submitting here https://hack.codingblocks.com/app/contests/1597/266/problem
also the complexity of solution is O(n+max(a[i]))

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.