Final answer:
The function getNumPeaks takes in an array of heights and returns the number of peaks in the hike.
Step-by-step explanation:
The function getNumPeaks takes in two parameters - an array of heights and the size of the array. It returns the number of peaks in the hike. To find the number of peaks, we can iterate through the array and compare each element with its adjacent elements. If an element is greater than both its adjacent elements, it is considered a peak. We keep track of the count of peaks and return it at the end of the function.
Example:
int getNumPeaks(const int heights[], int size) {
int count = 0;
for(int i = 1; i < size-1; i++) {
if(heights[i] > heights[i-1] && heights[i] > heights[i+1]) {
count++;
}
}
return count;
}
Learn more about getNumPeaks