
Donald W. answered 03/01/22
Senior Software Engineer with over 25 years of industry experience
I'm assuming we want the function to return true if mile is equal to the largest value in the array and false otherwise. I'm also going to assume that the heights array is not sorted and that it only contains non-negative values.
bool isPeak(const int height[], int arrSize, int mile) {
int peak = -1;
for (int i=0; i<arrSize; i++) {
peak = max(peak, height[i]);
}
return mile == peak;
}