We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
* WHEN N NOT IN(SELECT DISTINCT(P) FROM BST) THEN "Leaf" ELSE *
We want
N NOT IN(SELECT DISTINCT(P) FROM BST) to return True for nodes which are not present in attribute P
In SQL, NOT IN fails if the subquery returns even one NULL. The subquery return Null for Root node. When you do N NOT IN (...) and the list contains NULL, the result is unknown, so the whole WHEN condition is false, even for correct leaves. * ....WHEN N NOT IN(SELECT DISTINCT(P) FROM BST WHERE P IS NOT NULL) THEN "Leaf" ....* for desired result
NOTE :- ...WHERE P IS NOT NULL... for avoiding error due to edge cases
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Binary Tree Nodes
You are viewing a single comment's thread. Return to all comments →
* WHEN N NOT IN(SELECT DISTINCT(P) FROM BST) THEN "Leaf" ELSE * We want N NOT IN(SELECT DISTINCT(P) FROM BST) to return True for nodes which are not present in attribute P In SQL, NOT IN fails if the subquery returns even one NULL. The subquery return Null for Root node. When you do N NOT IN (...) and the list contains NULL, the result is unknown, so the whole WHEN condition is false, even for correct leaves. * ....WHEN N NOT IN(SELECT DISTINCT(P) FROM BST WHERE P IS NOT NULL) THEN "Leaf" ....* for desired result NOTE :- ...WHERE P IS NOT NULL... for avoiding error due to edge cases