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.
Approach: If parent p is null it is ROOT, For INNER parent P should not be null and child should be there, so number in Parent column P have a child so check if N number node present Parent p column then Inner
select
N,
CASE
when P is null then "Root"
when P is not null and N in (select distinct P from BST) then "Inner"
else "Leaf"
END as type_node
FROM BST
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
Binary Tree Nodes
You are viewing a single comment's thread. Return to all comments →
Approach: If parent p is null it is ROOT, For INNER parent P should not be null and child should be there, so number in Parent column P have a child so check if N number node present Parent p column then Inner
select N, CASE when P is null then "Root" when P is not null and N in (select distinct P from BST) then "Inner" else "Leaf" END as type_node FROM BST
order by N ASC