I am trying to solve the problem mentioned at the below link:
https://www.hackerrank.com/challenges/binary-search-tree-1/problem
I have written the following code. Please help me where i am going wrong
Select q.Node,case
WHEN q.Node NOT IN q.Parent THEN 'Leaf'
WHEN q.Node IN q.Parent AND q.Node NOT IN q.Higher_Parent THEN 'Inner'
WHEN q.Node IN q.Parent AND q.Node IN q.Higher_Parent THEN 'Root'
END as NodeType
from (
SELECT B1.N as Node,B1.P as Parent,B2.P as Higher_Parent FROM
BST B1 INNER JOIN BST B2
ON B1.P = B2.N
ORDER BY Node ASC
) q
N P HP
1 2 5
2 5 NULL
3 2 5
6 8 5
8 5 NULL
9 8 5
Where should I modify the above code to work. Sure there are other concise codes for the same problem but please help me with this code for learning purpose.
