My issue
for input 1 2 1 2 why answer was 1 ,actually it will change both 1’s to 2 ??
My code
# cook your dish here
t=int(input())
while(t):
t-=1
n=int(input())
l=list(map(int,input().split()))
stack=[]
ans=0
for i in range(n-1,-1,-1):
if len(stack)==0:
stack.append(l[i])
else:
if l[i]>=stack[-1]:
stack.pop()
stack.append(l[i])
else:
ans+=1
print(ans)
Problem Link: Stable Array Practice Coding Problem
