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.
WITH CTE AS (
SELECT x,y,(x+y) AS sm, abs(x-y) AS sb FROM functions
),
CTE2 AS(
SELECT *, row_number()
OVER(PARTITION BY sm, sb ORDER BY x) AS rnk FROM CTE)
SELECT y,x FROM cte2
WHERE rnk = 2
ORDER BY y;
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 →
WITH CTE AS ( SELECT x,y,(x+y) AS sm, abs(x-y) AS sb FROM functions ), CTE2 AS( SELECT *, row_number() OVER(PARTITION BY sm, sb ORDER BY x) AS rnk FROM CTE) SELECT y,x FROM cte2 WHERE rnk = 2 ORDER BY y;