We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
ngoccth_SQL SERVER:
WITH table_1 AS (
SELECT F1.X As X, F1.Y as Y, COUNT(F1.X) as num
FROM Functions AS F1
INNER JOIN Functions AS F2
ON F1.X = F2.Y AND F1.Y = F2.X AND F1.X <= F1.Y AND F2.X >= F2.Y
GROUP BY F1.X, F1.Y
)
SELECT X, Y from table_1 WHERE X != Y OR (X = Y AND num > 1) ORDER BY X
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Symmetric Pairs
You are viewing a single comment's thread. Return to all comments →
ngoccth_SQL SERVER: WITH table_1 AS ( SELECT F1.X As X, F1.Y as Y, COUNT(F1.X) as num FROM Functions AS F1 INNER JOIN Functions AS F2 ON F1.X = F2.Y AND F1.Y = F2.X AND F1.X <= F1.Y AND F2.X >= F2.Y GROUP BY F1.X, F1.Y ) SELECT X, Y from table_1 WHERE X != Y OR (X = Y AND num > 1) ORDER BY X