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.



  1. SELECT N,
  2. CASE
  3. WHEN P IS NULL THEN 'Root'
  4. WHEN N IN (SELECT P FROM BST) THEN 'Inner'
  5. ELSE 'Leaf'
  6. END
  7. FROM BST
  8. ORDER BY N;




codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube