If I have a list
l = [0, 0, 1, 2, 2, 2, 1, -1, -1, -1, 0]
I hope to obtain three zig-zag, a zig-zag is defined as local maxima (can be a plateau) and minima (can be a valley), as shown below, there are 3 zig zags, A, B, C while A and B overlap in the plateau, B and C overlap in the valley
A = [0, 0, 1, 2, 2, 2]
B = [2, 2, 2, 1, -1, -1, -1]
C = [-1, 0]