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 count(b2.P) > 0 and b1.P is null then 'Root'
when count(b2.P) > 0 and b1.P > 0 then 'Inner'
when count(b2.P) = 0 then 'Leaf'
end
from BST b1
left join BST b2 on b1.N = b2.P
group by b1.N,b1.P
order by b1.N asc
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 b1.N, case when count(b2.P) > 0 and b1.P is null then 'Root' when count(b2.P) > 0 and b1.P > 0 then 'Inner' when count(b2.P) = 0 then 'Leaf' end from BST b1 left join BST b2 on b1.N = b2.P group by b1.N,b1.P order by b1.N asc