Company: Infosys_1aug
Difficulty: easy
Highest Shared Value in a Mountain Array You are given a mountain array: it strictly increases to one peak and then strictly decreases. The peak itself is not part of either slope. Find the largest value that occurs on both the ascending slope (before the peak) and the descending slope (after the peak). If no such value exists, print -1 . Input Format The first line contains N , the size of the array. The second line contains N space-separated integers arr[0], arr[1], ..., arr[N-1] . Output Format Print the maximum value present on both slopes, or -1 if the slopes have no common value. Constraints 3 ≤ N ≤ 100,000 1 ≤ arr[i] ≤ 1,000,000,000 There is exactly one peak, it is not an endpoint, values strictly increase before it, and values strictly decrease after it. 32-bit signed integers suffice for the output. Examples Example 1 Input: 8 1 3 5 8 9 6 5 2 Output: 5 Example 2 Input: 7 2 4 6 8 10 3 1 Output: -1 Example 3 Input: 8 10 20 30 40 50 40 30 10 Output: 40 Notes The answer is a value