Need help in Count Subarrays SUBINC

Please help in debugging this code!
All of the test cases have been passed, just one showing TLE!

Link to question
Link to Solution

Thank you in Advance!
Any Optimization?!

Your code is worst case O(n^2) for a strictly increasing array. You can do this in O(n)

1 Like

@zeus_mmmut see bro you are literally counting the subarrays and then checking them whether they are increasing or not.
that is why you are getting TLE
so what you can do is instead of looping O ( n 2 )
just run the loop once and count till where the numbers are increasing and then you can use the formula of n(n+1)/2 - n for that and then start your counting again.

1 Like

Thank you so much for pointing it out! I did it in O(n)! :blush: