Hello, i am trying to solve this simple CP question, my approach works on the sample testcase but fails on the first hidden testcase
https://open.kattis.com/problems/upsanddownsofinvesting
my solution:
x, n, m = list(map(int, input().split()))
n-=1
m-=1
l=list(map(int, input().split()))
upordown=[1 if ((l[i+1]-l[i])>0) else -1 if ((l[i+1]-l[i])<0) else 0 for i in range(len(l)-1)]
if (x==1) or (x==2):
print("0 0")
else:
collapsed=[]
length=0
for i in range(len(upordown)-1):
if upordown[i]!=upordown[i+1]:
length+=upordown[i]
collapsed.append(length)
length=0
else:
length+=upordown[i]
collapsed.append(length+1 if length>0 else length-1)
ind=0
h=0
l=0
for i in range(len(collapsed)-1):
ind+=abs(collapsed[i])
if ((collapsed[i]>=n) and (abs(collapsed[i+1])>=n)):
h+=1
elif ((abs(collapsed[i])>=m) and (collapsed[i+1]>=m)):
l+=1
print(h,l)
i try to collapse the graph into a series of ups and downs, for example if its 1 3 5 2 that would be collapsed to [2,-1] in my solution to denote that there is 2 ups followed by one down. After i have the series of ups and downs i just need to check every i and i+1 to make sure its greater than the m or n that is given. it is guranteed that no point is the same so i dont really have to worry about 0s. im sure there is a much easier solution to this problem, but i can't wrap my head around what testcase im failing and whats wrong with my approach.