https://www.geeksforgeeks.org/problems/intersection-of-two-arrays2404/1?utm_source=geeksforgeeks&utm_medium=ml_article_practice_tab&utm_campaign=article_practice_tab //{ Driver Code Starts 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()); while (t-- > 0) { // First array input String[] str1 = br.readLine().trim().split( " "); // Read the first line and split by spaces int n = str1.length; int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(str1[i]); // Convert each element to an integer } // Second array input String[] str2 = br.readLine().trim().split( " "); // Read the second line and split by spaces int m = str2.length; int[] b = new int[m]; for (int i = 0; i < m; i++) { b[i] = Integer.parseInt(str2[i]); // Convert each element to an integer } Solution sln = new Solution(); System.out.println(sln.numberofElementsInIntersection(a, b)); } } } // } Driver Code Ends class Solution { public static int numberofElementsInIntersection(int a[], int b[]) { // Your code here HashSet al=new HashSet<>(); for(Integer i:a){ al.add(i); } int count=0; for(Integer i:b){ if(al.contains(i)){ count++; } } return count; } } ================================================================= int maxlen=0; HashMap hm=new HashMap<>(); int sum=0; int n=arr.length; for(int i=0;imaxlen){ maxlen=i+1; } } if(hm.containsKey(sum-k)){ int len=i-hm.get(sum-k); if(len>maxlen){ maxlen=len; } } if(!hm.containsKey(sum)){ hm.put(sum,i); } } return maxlen; ======================================== k=4 1 2 1 0 1 sum=1 sum=1+2=3 sum= 3+1=4 int max=Integer.MIN_VALUE; boolean found=false; for(int i=0;imax){ max=cmax; } } } } if(found==false) return 0; else return max; =============================================