select N, case when P is null then 'Root' WHEN N NOT IN (SELECT distinct P FROM BST) THEN 'Leaf' else 'Inner' end from BST order by N; When I try to use not in it's not working anyone know why? is it because null present in P?
I am getting an error using this, I know how to make it right (by removing Not) but why is it not showing the correct answer using this.?I did replace Leaf and Inner, Someone please help. select N, Case When P is NULL then 'Root' When N in(Select P from BST) then 'Leaf' else 'Inner' END from BST order by N
hackerrank is now having this some kind of glitch when part of your query ends up into the output that is why it causes error . To fix this simply do AS something after END statement . this query will work - SELECT N, CASE WHEN P IS NULL THEN 'Root' WHEN N IN (SELECT P from BST) THEN 'Inner' ELSE 'Leaf' END as SomeAlias FROM BST ORDER BY N;
Thank you, DEV19. I found it very difficult when I saw it first time. After watching this video I'm able to solve it in the time attempt.
In simple way explained TQ u
BRO, YOU ARE A GENIUS
select N,
case
when P is null then 'Root'
WHEN N NOT IN (SELECT distinct P FROM BST) THEN 'Leaf'
else 'Inner'
end
from BST order by N;
When I try to use not in it's not working anyone know why? is it because null present in P?
do I need to know the whole concept of binary tree to solve this question????
No Bro
thqqqqqq
I am getting an error using this, I know how to make it right (by removing Not) but why is it not showing the correct answer using this.?I did replace Leaf and Inner, Someone please help.
select N,
Case
When P is NULL then 'Root'
When N in(Select P from BST) then 'Leaf' else 'Inner'
END
from BST
order by N
hackerrank is now having this some kind of glitch when part of your query ends up into the output that is why it causes error . To fix this simply do AS something after END statement .
this query will work -
SELECT N,
CASE
WHEN P IS NULL THEN 'Root'
WHEN N IN (SELECT P from BST) THEN 'Inner'
ELSE 'Leaf'
END as SomeAlias
FROM BST
ORDER BY N;
@@sid_x_18 AS something after END isn't helping anymore :( any more ideas?
Try this:
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;
@@sushantkumar8208 It worked !
Sir pehle aap samajh lo