Hackerrank SQL Solutions | Binary Tree Nodes SQL Hackerrank Medium Problem
ฝัง
- เผยแพร่เมื่อ 16 พ.ค. 2020
- In this video I am solving "Binary Tree Nodes" with you. This is a Medium SQL Problem on Hackerrank. See also my other videos for more SQL Problems.
MSSQL Solution for this Problem:
SELECT N, 'Root' FROM BST WHERE P is null
UNION
SELECT N, 'Inner' FROM BST
EXCEPT
(Select N, 'Inner' FROM BST WHERE P is null)
EXCEPT
(SELECT N, 'Inner' FROM BST
EXCEPT
SELECT DISTINCT P, 'Inner' FROM BST WHERE P is not NULL)
UNION
SELECT N, 'Leaf' FROM BST
EXCEPT
SELECT DISTINCT P, 'Leaf' FROM BST WHERE P is not NULL
ORDER BY N ASC
;
____________________________________________
SUBSCRIBE!
Do you want to understand how to solve SQL Problems in every detail? That's what my channel is about. When I was younger I thought I could never program because it looked way too difficult. The truth is that it takes time but with some patience anybody can do it! Follow me along and get better!
____________________________________________
SUPPORT MY CHANNEL
🙌The best way to support my channel right now is to give me a Super Thanks. You can do that by clicking thanks next to the title of the video. It is much appreciated!
____________________________________________
💾GitHub: github.com/CuriosityLeonardo?...
✋Add me on LinkedIn to get in contact: / markus-friemann-221b3814b
Thanks sir
Good job friends,
Kindly provide the full table structure and also snippet.
Hi Satz, what do you mean by full table structure? can you explain?
Given a binary tree. For each tree node that has two children, swap the values of the child nodes (i.e., the values of their Data fields) c++?
Hi Shadow ISMAIL, I don't understand your question, can you frame it in a different way? Why do you write c++? This is a SQL Problem Solving video
Broo which data structure and algorithm used in sql ?? Bcozz I'm very confused for that plzz answer me as soon as possible....
Hey im using MSSQL.
@@thecodingmentor7701 which data structure and algorithms use in my sql??
@@funnycatvideos1199 I believe its relation data structure,
this is the type of structure in MS SQL and most SQL EXCEPT non-SQL databases
Can someone please explain to me what happened from 34:26 to 34:39?
Hi Rohan, Great Question!
3 Things happened:
1.
Corrected 'Inner' and renamed it 'Leaf'
2.
Added the Query of 'Inner' which I defined as all values except 'Root' and except 'Leaf'. I also put the solution in the description now to make it more clear.
3.
Ordered by N ASC
Greetings
Markus
@@thecodingmentor7701
Thank you so much Marcus. I loved your approach to the problem, unlike the other tutorials who only focus on the immediate solution. You broke down the question and took us through your thinking process.
Thanks and keep up the good work.
Use case
What do you mean Bhanu?
I am getting "SqlState 42000, Syntax error, permission violation, or other nonspecific error" when I tried to implement @ 12:48
Hi Vatsal, can you copy paste your code here so I can check it?
Greetings
SELECT N FROM BST WHERE P = {SELECT N FROM BST WHERE P IS null};
Above query gives "SqlState 42000, Syntax error, permission violation, or other nonspecific error" while using MS SQL Server
Also, 32:36 are LEAF Values, but INNER is mentioned in SQL. A bit confused
@@vatsalpatel492 If you use () instead of {} your code will work
@@vatsalpatel492 Yes you are right, that are LEAF Values, in 34:29 it is corrected
15 is not the number of nodes, its the value of the node right???
About what minute in the video are you talking?
@@thecodingmentor7701 I forgot actually, I had commented long time back. But generally about the trees, u said 15 is the number of nodes, but it's actually the value of that node.