//{ Driver Code Starts // Initial Template for Java import java.io.*; import java.util.*; public class GFG { public static void main(String args[]) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int t = Integer.parseInt(in.readLine().trim()); while (t-- > 0) { String line = in.readLine(); String[] tokens = line.split(" "); // Create an ArrayList to store the integers ArrayList array = new ArrayList<>(); // Parse the tokens into integers and add to the array for (String token : tokens) { array.add(Integer.parseInt(token)); } int[] arr = new int[array.size()]; int idx = 0; for (int i : array) arr[idx++] = i; int key = Integer.parseInt(in.readLine().trim()); out.println(new Solution().search(arr, key)); out.println("~"); } out.close(); } } // } Driver Code Ends // User function Template for Java class Solution { int search(int[] arr, int k) { // Complete this function int start=0; int end=arr.length-1; while(start<=end){ int mid=start+(end-start)/2; if(k==arr[mid]){ return mid; } if(arr[start]<=arr[mid]){ if(arr[start]<=k && k 0) { String arr[] = br.readLine().split(" "); int a[] = new int[arr.length]; for (int i = 0; i < arr.length; i++) { a[i] = Integer.parseInt(arr[i]); } Solution obj = new Solution(); int f = 0; int idx = obj.peakElement(a); int n = a.length; if (idx < 0 && idx >= n) System.out.println("false"); else { if (n == 1 && idx == 0) f = 1; else if (idx == 0 && a[0] > a[1]) f = 1; else if (idx == n - 1 && a[n - 1] > a[n - 2]) f = 1; else if (idx > 0 && idx < n && a[idx] > a[idx + 1] && a[idx] > a[idx - 1]) f = 1; else f = 0; if (f == 1) { System.out.println("true"); } else { System.out.println("false"); } } System.out.println("~"); } } } // } Driver Code Ends class Solution { public int peakElement(int[] arr) { // code here int start=0; int end=arr.length-1; while(start<=end){ int mid=start+(end-start)/2; if(mid!=0 && mid!=arr.length-1 && arr[mid]>=arr[mid-1] && arr[mid]>=arr[mid+1]){ return arr[mid]; }else if(arr[mid]>arr[mid-1]){ start=mid+1; }else{ end=mid-1; } } return -1; } } ==================================================