Company: Amazon
Question:
Question:
Given an array with distinct elements in such a way that first the elements stored in array are in increasing order and then after reaching to a peak element , elements stored are in decreasing order. Find the highest element.
Input:
The first line of input contains an integer T denoting the number of test cases. The first line of each test case consists of an integer n. The next line consists of n spaced integers.
The first line of input contains an integer T denoting the number of test cases. The first line of each test case consists of an integer n. The next line consists of n spaced integers.
Output:
Print the highest number in the array.
Print the highest number in the array.
Constraints:
1<=T<=100
1<=n<=100
1<=a[i]<=105
1<=T<=100
1<=n<=100
1<=a[i]<=105
Example:
Input:
2
11
1 2 3 4 5 6 5 4 3 2 1
9
1 3 4 5 7 8 9 5 2
Input:
2
11
1 2 3 4 5 6 5 4 3 2 1
9
1 3 4 5 7 8 9 5 2
Output:
6
9
6
9
Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Solution {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int m= sc.nextInt();
for(int mi=0;mi<m;mi++){
int n = sc.nextInt();
int [] ar= new int[n];
for(int i=0;i<n;i++){
ar[i]=sc.nextInt();
}
Arrays.sort(ar);
System.out.println(ar[ar.length-1]);
}
}
}
Time: 0.17
Comments
Post a Comment