题目描述
Given an unsorted array of integers. Find an element such that all the elements to its left are smaller and to its right are greater. Print -1 if no such element exists. Note that there can be more than one such element. In that case print the first such number occurring in the array.
Example 1:
Input: N = 7, arr[] = {4, 3, 2, 5, 8, 6, 7}
Output: 5
Explanation: To the left of element 5
every element is smaller to it and to
the right of element 5 every element
is greater to it.
Example 2:
Input: N = 7, arr[] = {5, 6, 2, 8, 10, 9, 8}
Output: -1
Explanation: No such desired element is
present in the array.
Your Task:
This is a function problem. You don't need to take any input, as it is already accomplished by the driver code. You just need to complete the function FindElement() that takes array arr and integer N as parameters and returns the desired output.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1 ≤ N ≤ 10^{6}
输入格式
见题面
输出格式
见题面