Problem Statement:
You are charting an athlete's altitude readings during a jog, represented by R. It is stored in an integer array A where the route naturally forms plateaus where altitude never decreases for a while and then drops.
You have to split array A into maximal non-decreasing runs (plateaus). For each plateau, add the (last - first) value of that run to a total. Your task is to find and return an integer value representing the sum of all maximal non-decreasing runs of (last_value - first_value).
Note: A "run" is a maximal segment you can't extend without breaking the non-decreasing property; i.e., within a run a[i] <= a[i+1], and the next element after the run is smaller (or the array ends).
Input Specification:
Output Specification:
Example 1:
Input:
input1 : 7
input2 : {2, 2, 5, 4, 4, 6, 1}
Output:
5
Explanation:
Here, R = 7 and A = {2, 2, 5, 4, 4, 6, 1}. Plateaus (maximal non-decreasing runs) are as below:
Total = 3 + 2 + 0 = 5. Hence, 5 is returned as the output.