Want to know the time complexity inner for loop which is partially iterating the array
It is $O(n^2)$. Consider array = [n, n-1, n-2, ..., 1].



BTW, you could implement this in $O(n)$ by scanning from the end of the array:


Suppose the next-increasing-value (NIV) of a[i+1] is x.
We want to find the NIV of a[i], which we observe that:


If a[i+1] &gt; a[i], then the NIV is a[i+1]
If x &gt; a[i], then the NIV is x
Otherwise, a[i] is already the maximum value, so the NIV = -1.



Using this we could work backward from a[n-1] to a[0] to find the NIV of each entry in $O(n)$ time.