Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@avaiesshaik782 | 782 |

@arpitsatnalika | 777 |

@tujhekya | 602 |

@prakharxyz | 601 |

@code_it_ | 591 |

@iamronak | 505 |

@imnm | 500 |

@pradeepkumarjad | 488 |

@satyam0460 | 481 |

@nitesha125 | 468 |

@Rahul Jadhav 1 | 466 |

Complete Leaderboard |

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.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. First line of each test case contains an Integer N denoting size of array and the second line contains N space separated array elements.

**Output:**

For each test case, in a new line print the required element. If no such element present in array then print -1.

**Constraints:**

1 <= T <= 100

3 <= N <= 10^{6}

1 <= A[i] <= 10^{6}

**Example:
Input:**

3

4

4 2 5 7

3

11 9 12

6

4 3 2 7 8 9

**Output:**

5

-1

7

**Explanation:
Testcase 1 :** Elements on left of 5 are smaller than 5 and on right of it are greater than 5.

Login 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?

Yes
Element with left side smaller and right side greater

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.