@coderArmy - Day1 Array Equal or not

1 min read
using map
sorting and comparison
nested loops
class Solution{
public:
bool check(vector<ll> A, vector<ll> B, int N) {
unordered_map<long,long> mp;
for(long long i=0 ; i<N ; i++ ){mp[A[i]]++;}
for(long long i=0 ; i<N ; i++ ){mp[B[i]]--;}
for(auto i=mp.begin();i!=mp.end();i++) {
if(i->second!=0) return false;
}
return true;
}
};
class Solution{
public:
bool check(vector<ll> A, vector<ll> B, int N) {
sort(A.begin(),A.end());
sort(B.begin(),B.end());
for(int i=0; i<N ; i++){if(A[i] != B[i]) return false;}
return true;
}
};
0
Subscribe to my newsletter
Read articles from karan arora directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
