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 Distinct N,
CASE
WHEN P is null THEN 'Root'
WHEN c.P is null THEN 'Leaf'
ELSE 'Inner' END as Value
FROM (SELECT A.N as N,B.P as P,A.P as root FROM BST A LEFT OUTER JOIN BST B ON A.N=B.P)as c 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 →
My SQL:
SELECT Distinct N, CASE WHEN P is null THEN 'Root' WHEN c.P is null THEN 'Leaf' ELSE 'Inner' END as Value FROM (SELECT A.N as N,B.P as P,A.P as root FROM BST A LEFT OUTER JOIN BST B ON A.N=B.P)as c ORDER BY N