Handle Score
@Ibrahim Nash 6379
@blackshadows 6329
@mb1973 5358
@Quandray 5231
@akhayrutdinov 5111
@saiujwal13083 4510
@sanjay05 3762
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3357
@KshamaGupta 3318
Complete Leaderboard
Element with left side smaller and right side greater
Easy Accuracy: 43.26% Submissions: 2227 Points: 2

Given an unsorted array of size N. Find the first element in array such that all of its left elements are smaller and all right elements to it are greater than it.

Note: Left and right side elements can be equal to required element. And extreme elements cannot be required element.


Example 1:

N = 4
A[] = {4, 2, 5, 7}
Elements on left of 5 are smaller than 5
and on right of it are greater than 5.


Example 2:

N = 3
A[] = {11, 9, 12}


Your Task:  
You don't need to read input or print anything. Your task is to complete the function findElement() which takes the array A[] and its size N as inputs and returns the required element. If no such element present in array then return -1.


Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)


3 <= N <= 106
1 <= A[i] <= 106

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Element with left side smaller and right side greater

Output Window