@coderArmy - Day1 Array Equal or not

karan arorakaran arora
1 min read
  1. using map

  2. sorting and comparison

  3. 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

karan arora
karan arora