Created
May 5, 2017 19:27
-
-
Save amilie/359b6240b448d9a84e069dce28b49ce0 to your computer and use it in GitHub Desktop.
My solution to the BST challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- https://www.hackerrank.com/challenges/binary-search-tree-1 | |
select node, type from ( | |
(select N as node, "Root" as type from BST where P is null) | |
union | |
(select t1.N as node, "Leaf" as type from BST t1 | |
left join BST t2 on t1.N = t2.P | |
where t2.P is null) | |
union | |
(select distinct t1.N as node, "Inner" as type from BST t1 | |
left join BST t2 on t1.N = t2.P | |
where t1.P is not null and t2.P is not null) | |
) as U order by node; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment