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 b1.n, case
when n = (select n from bst where p is NULL) then 'Root'
when b1.n in (select b2.n from bst b2
left join bst b3 ON b2.n=b3.p
where b3.p IS NULL) then 'Leaf'
else 'Inner'
end
from bst b1
order by n asc
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Binary Tree Nodes
You are viewing a single comment's thread. Return to all comments →
select b1.n, case when n = (select n from bst where p is NULL) then 'Root' when b1.n in (select b2.n from bst b2 left join bst b3 ON b2.n=b3.p where b3.p IS NULL) then 'Leaf' else 'Inner' end from bst b1 order by n asc