+-------------+------+
|Column Name |Type|+-------------+------+
| X | int || Y | int |+-------------+------+
Eachrow includes X and Y, wherebothare integers. Table may contain duplicate values.
Two coordindates (X1, Y1) and (X2, Y2) are said to be symmetric coordintes if X1 == Y2 and X2 == Y1.
Write a solution that outputs, among all these symmetriccoordintes , only those unique coordinates that satisfy the condition X1 <= Y1.
Return the result table ordered byXandY(respectively)inascending order.
Input:
Coordinates table:+----+----+| X | Y |+----+----+|20|20||20|20||20|21||23|22||22|23||21|20|+----+----+Output:
+----+----+| x | y |+----+----+|20|20||20|21||22|23|+----+----+Explanation:
-(20,20) and (20,20) are symmetric coordinates because, X1 == Y2 and X2 == Y1. This results indisplaying(20,20) as a distinctive coordinates.-(20,21) and (21,20) are symmetric coordinates because, X1 == Y2 and X2 == Y1. However, only (20,21) will be displayed because X1 <= Y1.-(23,22) and (22,23) are symmetric coordinates because, X1 == Y2 and X2 == Y1. However, only (22,23) will be displayed because X1 <= Y1.The output table is sorted by X and Y in ascending order.
We join the table with itself to find symmetric pairs (X1, Y1) and (X2, Y2) such that X1 = Y2 and X2 = Y1. We only keep unique pairs where X1 <= Y1 and order the result as required.