In the below code, for every time in the loop the a[s[-1]] will check all the elements of array or only the i th element of array.can any one explain it

for i in range(n):
while len(s )!=0 and a[s[-1]] > a[i]: