HTML & JS
/*Please note that it's Function problem i.e.
you need to write your solution in the form of Function(s) only.
Driver Code to call/invoke your function is mentioned above.*/

/*Complete the function below*/
void printDuplicates(int arr[], int n)
{
    map<int,int> m;
    map<int,int>::iterator it;
    int flag = 0;
    for(int i=0;i<n;i++)
    {
        it = m.find(arr[i]);
        if(it == m.end())
            m.insert(pair<int,int>(arr[i],1));
        else
            it->second+=1;
    }
    for(it = m.begin();it!=m.end();it++)
        if(it->second >= 2)
        {
            flag = 1;
            cout<<it->first<<" ";
        }
    if(!flag)
        cout<<-1;
    m.clear();
}

Generated URL:

Compile Errors :

prog.cpp: In function 'void printDuplicates(int*, int)':
prog.cpp:8:5: error: 'map' was not declared in this scope
     map<int,int> m;
     ^
prog.cpp:8:9: error: expected primary-expression before 'int'
     map<int,int> m;
         ^
prog.cpp:9:9: error: expected primary-expression before 'int'
     map<int,int>::iterator it;
         ^
prog.cpp:13:9: error: 'it' was not declared in this scope
         it = m.find(arr[i]);
         ^
prog.cpp:13:14: error: 'm' was not declared in this scope
         it = m.find(arr[i]);
              ^
prog.cpp:15:22: error: 'pair' was not declared in this scope
             m.insert(pair<int,int>(arr[i],1));
                      ^
prog.cpp:15:27: error: expected primary-expression before 'int'
             m.insert(pair<int,int>(arr[i],1));
                           ^
prog.cpp:15:31: error: expected primary-expression before 'int'
             m.insert(pair<int,int>(arr[i],1));
                               ^
prog.cpp:19:9: error: 'it' was not declared in this scope
     for(it = m.begin();it!=m.end();it++)
         ^
prog.cpp:19:14: error: 'm' was not declared in this scope
     for(it = m.begin();it!=m.end();it++)
              ^
prog.cpp:23:13: error: 'cout' was not declared in this scope
             cout<<it->first<<" ";
             ^
prog.cpp:26:9: error: 'cout' was not declared in this scope
         cout<<-1;
         ^
prog.cpp:27:5: error: 'm' was not declared in this scope
     m.clear();
     ^

Output:

No Output
Report Bug