Answers for "codingninja"

0

codingninja

import java.util.*;

public class Solution{
	
	public static void intersection(int[] arr1, int[] arr2){
 		
        Arrays.sort(arr1);
        Arrays.sort(arr2);
        
        int n = arr1.length;
        int m = arr2.length;
        
        int i = 0;  // pointer starts at arr1
        int j = 0;  // pointer starts at arr2;
        
        while(i < n && j < m){
            if(arr1[i] == arr2[j]) {
                System.out.print(arr1[i] + " ");
                i++;
                j++;
            } else if(arr1[i] < arr2[j])
                i++;
            else
                j++;
        }
    }
}
Posted by: Guest on October-22-2020

Code answers related to "codingninja"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language