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.
if in case column (N) dosent have all the required values.
with tbl1 as (select distinct(N) from bst),
tbl2 as (select distinct(P) from bst),
tbl3 as ( Select N from tbl1 union Select P from tbl2),
tbl4 as ( select * from tbl3 where N is not null)
Select *, Case
when tbl4.N in (Select * from tbl2 where P in (select N from BST where P is not null)) then "Inner"
when tbl4.N in (Select N from BST where P is null)then "Root"
ELSE 'Leaf'
end as node_type
from tbl4
order by 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 →
if in case column (N) dosent have all the required values.
with tbl1 as (select distinct(N) from bst), tbl2 as (select distinct(P) from bst), tbl3 as ( Select N from tbl1 union Select P from tbl2), tbl4 as ( select * from tbl3 where N is not null)
Select *, Case when tbl4.N in (Select * from tbl2 where P in (select N from BST where P is not null)) then "Inner" when tbl4.N in (Select N from BST where P is null)then "Root" ELSE 'Leaf' end as node_type from tbl4 order by N