Time complexity : ================== rate at which time increase wrt variables its called time complexity Ignore constants Igone lower values for() { } if() { } else{ } 0(n)+0(k) ~ 0(n) ============================================ for() { } for() { for(){ } } 0(n^2)+0(n) ~ 0(n^2) ===================================== for() { for(){ for() { } } } ================================== Java Quick Sort 0(nlog(n)) nlog(n) +0(n^2) ============================== Arrays.sort(arr) for(){ for(){ }} ====================================== Space complexity: ================== 0(1) if you are using Any Collection ie 0(n) array, arraylist,hashset, hashmap, ======================================= //{ Driver Code Starts // Initial Template for Java import java.io.*; import java.lang.*; import java.util.*; class GFG { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); while (t-- > 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 max=Integer.MIN_VALUE; int index=-1; for(int i=0;imax){ max=arr[i]; index=i; } } return index; } } ============================================= //{ Driver Code Starts // Initial Template for Java import java.io.*; import java.util.*; class GFG { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine().trim()); // Inputting the testcases while (t-- > 0) { String line = br.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(Long.parseLong(token)); } int[] arr = new int[array.size()]; int idx = 0; for (long i : array) arr[idx++] = (int)i; Solution obj = new Solution(); // calling maxSubarraySum() function System.out.println(obj.firstRepeated(arr)); System.out.println("~"); } } } // } Driver Code Ends // User function Template for Java class Solution { // Function to return the position of the first repeating element. public static int firstRepeated(int[] arr) { // Your code here HashMap hm=new HashMap<>(); int ans=-1; for(int i=arr.length-1;i>=0;i--){ if(hm.containsKey(arr[i])){ ans=i+1; }else{ hm.put(arr[i],1); } } return ans; } } ==================================================================