This is what I was able to write for w = 2.
A = [1,2,3,2,1,4,3,2,5,1,2,6,1,2,7]
w = 2
for i in range(w, len(A)- w):
for j in range(w):
if A[i] > A[j] and A[i] > A[i-1]:
if A[i] > A[j+4] and A[i] > A[i+1]:
print(A[i])
Output: 3
4
5
5
6
6
The first output is 3 (1,2,3,2,1) which is max out of it's left 'w' elements 1,2 and right 'w' elements 2,1. Similarly, the second output 4 derived from from (2,1,4,3,2) and so on.
How do I extend this for w = n, where n = 3, 4, 5 ?