928. Find All Symmetric Pairs

You are given an array of integer pairs pairs, where each pair is represented as a 2-element array [a, b]. A pair [a, b] is said to be symmetric to another pair [c, d] if a == d and b == c.

Return all symmetric pairs from the input array. If multiple symmetric pairs exist, include each only once and in the order they appear in the input. Return each symmetric pair in the format [a, b], where a > b.

Example 1:

Input: pairs = [[1,2],[2,1],[3,4],[4,5],[5,4]]

Output: [[2,1],[5,4]]

Explanation:

  • [1,2] and [2,1] → symmetric
  • [4,5] and [5,4] → symmetric
  • Result includes [2,1] and [5,4].

Example 2:

Input: pairs = [[1,5],[2,3],[4,2],[5,1],[2,4]]

Output: [[2,4],[5,1]]

Explanation:

  • [4,2] and [2,4] → symmetric
  • [1,5] and [5,1] → symmetric

Now Your Turn!

Pick the correct output for the given input

Input: pairs = [[7,8],[8,9],[9,7],[9,8],[8,7]]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= pairs.length <= 105
  • Each pair[i] contains exactly two integers: 0 <= pair[i][0], pair[i][1] <= 106
0
class Solution {
public:
vector<vector<int>> findSymmetricPairs(vector<vector<int>>& pairs) {
// Your code goes here
}
};
Test Case

Input:

Pairs