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_tree as (
select distinct a.n as node from bst a join bst b on a.n=b.p
)select (case when p is null and n in (select * from cte_tree)
then concat(convert(varchar(4),n),' Root') when n in (select * from cte_tree)
then concat(convert(varchar(4),n),' Inner') else concat(convert(varchar(4),n),' Leaf')
end) as num from bst order by n
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Binary Tree Nodes
You are viewing a single comment's thread. Return to all comments →
with cte_tree as ( select distinct a.n as node from bst a join bst b on a.n=b.p )select (case when p is null and n in (select * from cte_tree) then concat(convert(varchar(4),n),' Root') when n in (select * from cte_tree) then concat(convert(varchar(4),n),' Inner') else concat(convert(varchar(4),n),' Leaf') end) as num from bst order by n