My issue
I am getting a runtime error. Not able to find out what is it although the code is working in other idles
My code
t = int(input())
for _ in range(t):
n, r = map(int, input().split())
rating = list(map(int, input().split()))
counter = True
if rating[1] >= rating[0]:
low = rating[0]
high = rating[0]
for j in range(2, n): # Use a different variable name here (e.g., j)
if low < rating[j] < high:
high = rating[j]
elif rating[j] > high:
low = high
high = rating[j]
else:
counter = False
break
else:
low = rating[1]
high = rating[0]
for j in range(2, n): # Use a different variable name here (e.g., j)
if low < rating[j] < high:
high = rating[j]
elif rating[j] < low:
high = low
low = rating[j]
else:
counter = False
break
if counter:
print('YES')
else:
print('NO')
Problem Link: Chef goes Left Right Left Practice Coding Problem - CodeChef