Find duplicates in an array: question from GeeksForGeeks

Question link: https://practice.geeksforgeeks.org/problems/find-duplicates-in-an-array/1/?track=interview-arrays
Input:
25
6 23 8 19 13 22 9 23 16 8 2 11 22 1 15 1 22 22 8 5 11 19 8 11 5

Its Correct output is:
23 8 22 1 11 19 5

And Your Code’s output is:
1 5 8 11 19 22 23

Can you all see the difference? My output is right but since it is sorted I am getting Wrong Answer.
This is because I have used std::map<K,V> .
So when I iterate over it, it iterates based on the sorted order,
not the order that I inserted elements.

Can someone help? Is there any alternative?
Here is my code : https://ide.geeksforgeeks.org/eZKvGIdmXs

You need to print the numbers in the order the get their duplicates in the array.

Just when you get the duplicate of some number, just print it instead of iterating the map …

You check this: https://ide.geeksforgeeks.org/ypx0u5Si1u

Thanks alot!

//