Find 3 Peak And Valley In An Array Separated By N Indices

Given an array of size n, we have to find 3 peak values and 3 trough values in the array such that each peak values are separated by another peak value by n entries.
Similarly, each trough value must be n days separated from the other trough values. For eg:

int arr[] = {1, 5, 6, 4, 3, 3, 10, 2, 8, 6, 11, 4, 10};
int distance = 2;

In above example, peak values are – 6, 10 and 11 (which are 2 indices apart).

valley values are – 1, 3 and 2 (which are 2 indices apart).

(more…)
Find 3 Peak And Valley In An Array Separated By N Indices Read More