#C11366. Valley Counting
Valley Counting
Valley Counting
You are given a sequence of integer data points represented as space-separated values. Your task is to count the number of valleys in the sequence. A valley is defined as a contiguous subsequence that resembles the capital letter V. In other words, a valley occurs at an index i if:
[ sequence[i-1] > sequence[i] < sequence[i+1] ]
Once a valley is detected, proceed through the sequence until the valley ends (i.e. while the sequence is non-decreasing). Output the total number of valleys detected in the sequence.
Note: The input will be given as one single line containing space-separated integers.
inputFormat
The input consists of a single line containing space-separated integers representing the data sequence.
Example Input:
3 2 1 2 3 4 3 2 1 0 1 2
outputFormat
Output a single integer: the number of valleys found in the sequence.
Example Output:
2## sample
3 2 1 2 3 4 3 2 1 0 1 2
2