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 cte1 as (select x, y, row_number() over( order by x) as ro_num from Functions),
cte2 as (select x, y from cte1 oq
where y in (select x from cte1 where ro_num != oq.ro_num and y = oq.x))
select top((select count(*) from cte2)/2) x, y from cte2 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 →
My solution:
with cte1 as (select x, y, row_number() over( order by x) as ro_num from Functions), cte2 as (select x, y from cte1 oq where y in (select x from cte1 where ro_num != oq.ro_num and y = oq.x)) select top((select count(*) from cte2)/2) x, y from cte2 order by x;