Monday, 17 October 2016

Ransom Note (CTCI)

Problem: Ransom Note

bool ransom_note(vector<string> magazine, vector<string> ransom) {
    map<string, int> hashMap;
    for(int i=0;i<magazine.size();i++)
        hashMap[magazine[i]]++;
    for(int i=0;i<ransom.size();i++)
        if(hashMap[ransom[i]]>0)
            hashMap[ransom[i]]--;
        else return false;
    return true;
}

No comments:

Post a Comment