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.
tried in oracle let me know if this cna optimized further.
select num, case when (select N from bst where p is null)=num then 'Root' when (select count(N) from bst where n=num)=1 and (select count(P) from bst where p=num)>1 then 'Inner' when (select count(N) from bst where n=num)=1 and (select count(P) from bst where p=num)=0 then 'Leaf' end from (
select N num from bst
union
select P num from bst) where num is not null;
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 →
tried in oracle let me know if this cna optimized further.
select num, case when (select N from bst where p is null)=num then 'Root' when (select count(N) from bst where n=num)=1 and (select count(P) from bst where p=num)>1 then 'Inner' when (select count(N) from bst where n=num)=1 and (select count(P) from bst where p=num)=0 then 'Leaf' end from ( select N num from bst union select P num from bst) where num is not null;