#K73432. Peak Element in a Mountain Array
Peak Element in a Mountain Array
Peak Element in a Mountain Array
You are given a mountain array (i.e. an array that is strictly increasing and then strictly decreasing). Your task is to find the peak element in the array. The peak element is defined as the element where:
\(a[0] < a[1] < \cdots a[p+1] > \cdots > a[n-1]\), where \(0 \le p < n\).
Your solution must run in \(O(\log n)\) time, and you are encouraged to use a binary search approach.
Input Format: The first line contains an integer representing the number of test cases. For each test case, the first line contains a single integer \(n\) (the size of the array), and the second line contains \(n\) space-separated integers representing the mountain array.
Output Format: For each test case, output a single line containing the peak element.
inputFormat
The input begins with an integer \(T\) denoting the number of test cases. Each test case has the following format:
- An integer \(n\) on a separate line, representing the length of the mountain array.
- A line with \(n\) space-separated integers, representing the elements of the array.
outputFormat
For each test case, output the peak element (the maximum element in the mountain array) on a separate line.
## sample1
5
1 2 3 2 1
3
</p>