Because your time complexity is O(N^2) simple…Your algorithm is traversing like this

**n + (n-1) + (n-2) + … + 1**

* Making total operations as N(N+1)/2 which is O(N^2)…**

Hence TLE as N<=1000000…

Try to see for a pattern…

1 Like