https://open.kattis.com/problems/upsanddownsofinvesting
my solution works for the first two testcases but fails on the first real one.
To summarize the problem
given a graph you are supposed to find the peaks and throughs, i do this by calculating the number of consecutive changes in one direction so if i have the graph 5 6 9 8 5 4 i will collapse it to 2, -3.
I then iterate through the collapsed list and check if every i and i+1 is greater than the n or m (the number of consecutive rises/falls) they want and if so then it is a through. i cant think of a scenario where my solution fails can someone help me
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)