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.
select
distinct
b1.n,
case
when b2.p is null then 'Leaf'
when b1.p is null then 'Root'
else 'Inner'
end as n_type
from BST as b1
left join BST as b2 on b1.n = b2.p
order by b1.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 →
select distinct b1.n, case when b2.p is null then 'Leaf' when b1.p is null then 'Root' else 'Inner' end as n_type from BST as b1 left join BST as b2 on b1.n = b2.p order by b1.n