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
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool areSame ( vector < int > & a , vector < int > & b ) { if ( a . size ( ) != b . size ( ) ) return false ; unordered_map < int , int > m1 , m2 ; for ( int i = 0 ; i < a . size ( ) ; i ++ ) { m1 [ a [ i ] ] ++ ; m2 [ b [ i ] ] ++ ; } for ( auto x : m1 ) { if ( m2 . find ( x . first ) == m2 . end ( ) m2 [ x . first ] != x . second ) return false ; } return true ; } int main ( ) { vector < int > a ( { 7 , 7 , 5 } ) , b ( { 7 , 7 , 5 } ) ; if ( areSame ( a , b ) ) cout << " Yes STRNEWLINE " ; else cout << " No STRNEWLINE " ; return 0 ; }