Multiset Equivalence Problem | C # program to check if two given multisets are equivalent ; Create two unordered maps m1 and m2 and insert values of both vectors . ; Now we check if both unordered_maps are same of not . ; Driver code
using System ; using System . Collections . Generic ; class GFG { static bool areSame ( int [ ] a , int [ ] b ) { if ( a . Length != b . Length ) return false ; 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 ) ; } } foreach ( KeyValuePair < int , int > x in m1 ) { if ( ! m2 . ContainsKey ( x . Key ) m2 [ x . Key ] != x . Value ) return false ; } return true ; } public static void Main ( String [ ] args ) { int [ ] a = { 7 , 7 , 5 } ; int [ ] b = { 7 , 7 , 5 } ; if ( areSame ( a , b ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }