We use unordered_map for hashing. We iterate once through our array of size N. If we find element that has not been seen yet, nor its opposite we increment value of this element in map. And we find the pair we increment their values in map to 2 and we push_back this pair in right order to our output. Time complexity is O(N).
We use unordered_map for hashing. We iterate once through our array of size N. If we find element that has not been seen yet, nor its opposite we increment value of this element in map. And we find the pair we increment their values in map to 2 and we push_back this pair in right order to our output. Time complexity is O(N).