Challenge: Find Symmetric Pairs in an Array
Now we will implement a symmetry detection algorithm using hash tables.
We'll cover the following
Problem Statement #
By definition, (a, b) and (c, d) are symmetric pairs iff, a = d
and b = c
. In this problem, you have to implement the findSymmetric(list)
function which will find all the symmetric pairs in the given array.
Input #
An array of pairs. The first element of each pair would be unique.
Output #
An array containing all the symmetric pairs of integers in the input array.
Sample Input #
var list = [[1, 2], [3, 4], [5, 9], [4, 3], [9, 5]]
Sample Output #
[[3, 4], [4, 3], [5, 9], [9, 5]]
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.