Find Union and Intersection of two unsorted arrays | C # code to find intersection when elements may not be distinct ; Function to find intersection ; when both are equal ; Driver Code ; sort ; Function call
using System ; class GFG { static void intersection ( int [ ] a , int [ ] b , int n , int m ) { int i = 0 , j = 0 ; while ( i < n && j < m ) { if ( a [ i ] > b [ j ] ) { j ++ ; } else if ( b [ j ] > a [ i ] ) { i ++ ; } else { Console . Write ( a [ i ] + " ▁ " ) ; i ++ ; j ++ ; } } } public static void Main ( ) { int [ ] a = { 1 , 3 , 2 , 3 , 4 , 5 , 5 , 6 } ; int [ ] b = { 3 , 3 , 5 } ; int n = a . Length ; int m = b . Length ; Array . Sort ( a ) ; Array . Sort ( b ) ; intersection ( a , b , n , m ) ; } }