Create two unordered maps m1 and m2 and insert values of both vectors .
Dictionary < int , int > m1 , m2 ; m1 = new Dictionary < int , int > ( ) ; m2 = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < a . Length ; i ++ ) { if ( m1 . ContainsKey ( a [ i ] ) ) { m1 [ a [ i ] ] = m1 [ a [ i ] ] + 1 ; } else { m1 . Add ( a [ i ] , 1 ) ; } if ( m2 . ContainsKey ( b [ i ] ) ) { m2 [ b [ i ] ] = m2 [ b [ i ] ] + 1 ; } else { m2 . Add ( b [ i ] , 1 ) ; } }