Skip to content

2978. Symmetric Coordinates

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
WITH
  SymmetricCoordinates AS (
    SELECT DISTINCT C1.x, C1.y
    FROM Coordinates AS C1
    INNER JOIN Coordinates AS C2
      ON (C1.x, C1.y) = (C2.y, C2.x)
    WHERE C1.x < C1.y
    UNION ALL
    SELECT x, y
    FROM Coordinates
    WHERE x = y
    GROUP BY 1
    HAVING COUNT(*) > 1
  )
SELECT x, y
FROM SymmetricCoordinates
ORDER BY 1, 2;