[Solved] Algo Homework 02-Peak Finding Problem

$25

File Name: Algo_Homework_02-Peak_Finding_Problem.zip
File Size: 348.54 KB

SKU: [Solved] Algo Homework 02-Peak Finding Problem Category: Tag:
5/5 - (1 vote)

Given an array of integers. Find a peak element in it. An array element is peak if it is NOT smaller than its neighbors. For example, for input array {5, 10, 20, 15}, 20 is the only peak element.

For corner elements, we need to consider only one neighbor. Following corner cases give better idea about the problem.

1) If input array is sorted in strictly increasing order, the last element is always a peak element. For example, 50 is peak element in {10, 20, 30, 40, 50}. 2) If input array is sorted in strictly decreasing order, the first element is always a peak element. 100 is the peak element in {100, 80, 60, 50, 20}.

3) If all elements of input array are same, every element is a peak element.

Sample input

5,10,20,15

100,80,60,50,20

10,20,30,40,50

Sample output

Find it! The peak element is 20

Find it! The peak element is 100 Find it! The peak element is 50

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] Algo Homework 02-Peak Finding Problem
$25