We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Data Structures
  3. Arrays
  4. Sparse Arrays
  5. Discussions

Sparse Arrays

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • shivams359
    5 years ago+ 4 comments

    Here is my simple code for this:

    int main() 
    {
        int n,i,m,j;
        cin>>n;
        string s[n];
        for(i=0;i<n;i++)
        {
            cin>>s[i];
        }
        cin>>m;
        string t[m];
        for(i=0;i<m;i++)
        {
            cin>>t[i];
        }
        for(i=0;i<m;i++)
        {
            int flag=0;
            for(j=0;j<n;j++)
            {
                if(t[i]==s[j])
                    flag++;
            }
            cout<<flag<<"\n";
        }
        return 0;
    }
    
    13|
    Permalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature