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 f1_temp as (
select x, y, count(*) as cnt
from functions
where x <= y
group by x , y
)
, f2_temp as(
select x, y
from functions
where x > y
)
select f1.x, f1.y
from f1_temp f1
where f1.cnt >1
or (
f1.x in (select f2.y from f2_temp f2 )
and f1.y in (select f2.x from f2_temp f2 )
)
order by f1.x asc
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 f1_temp as ( select x, y, count(*) as cnt from functions where x <= y group by x , y )
, f2_temp as( select x, y from functions where x > y )
select f1.x, f1.y from f1_temp f1 where f1.cnt >1 or ( f1.x in (select f2.y from f2_temp f2 ) and f1.y in (select f2.x from f2_temp f2 ) ) order by f1.x asc