Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 651 Bytes

Nuts and Bolts Problem.md

File metadata and controls

27 lines (20 loc) · 651 Bytes
 void matchPairs(int n, char nuts[], char bolts[]) {
       
        vector<char> expected= { '!','#','$','%','&','*','?','@','^' };
        
        unordered_map<char,int>mp;
        
        for(int i=0;i<n;i++)
            mp[nuts[i]]++;
            
        int i=0;
            
        for(auto it: expected)
        {
            while(i<n && mp[it]>0)
            {
                nuts[i]=it;
                bolts[i]=it;
                i++;
                mp[it]--;
            }
        }
    }