HackerRank MySQL - Binary Tree Nodes
You are given a table, BST, containing two columns: N and P, where N represents the value of a node in Binary Tree, and P is the parent of N.
- SELECT N,
- CASE
- WHEN P IS NULL THEN 'Root'
- WHEN N IN (SELECT P FROM BST) THEN 'Inner'
- ELSE 'Leaf'
- END
- FROM BST
- ORDER BY N;