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

ความคิดเห็น • 23

  • @imranwahid9871
    @imranwahid9871 3 ปีที่แล้ว

    Thanks sir

  • @princesspraniti6237
    @princesspraniti6237 2 ปีที่แล้ว

    Good job friends,
    Kindly provide the full table structure and also snippet.

    • @thecodingmentor7701
      @thecodingmentor7701  2 ปีที่แล้ว +1

      Hi Satz, what do you mean by full table structure? can you explain?

  • @DJ-SD
    @DJ-SD 2 ปีที่แล้ว

    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++?

    • @thecodingmentor7701
      @thecodingmentor7701  2 ปีที่แล้ว

      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

  • @funnycatvideos1199
    @funnycatvideos1199 2 ปีที่แล้ว

    Broo which data structure and algorithm used in sql ?? Bcozz I'm very confused for that plzz answer me as soon as possible....

    • @thecodingmentor7701
      @thecodingmentor7701  2 ปีที่แล้ว +1

      Hey im using MSSQL.

    • @funnycatvideos1199
      @funnycatvideos1199 2 ปีที่แล้ว

      @@thecodingmentor7701 which data structure and algorithms use in my sql??

    • @amgdhussein7040
      @amgdhussein7040 2 ปีที่แล้ว

      @@funnycatvideos1199 I believe its relation data structure,
      this is the type of structure in MS SQL and most SQL EXCEPT non-SQL databases

  • @rohandeshpande2264
    @rohandeshpande2264 3 ปีที่แล้ว +1

    Can someone please explain to me what happened from 34:26 to 34:39?

    • @thecodingmentor7701
      @thecodingmentor7701  3 ปีที่แล้ว +1

      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

    • @rohandeshpande2264
      @rohandeshpande2264 3 ปีที่แล้ว

      @@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.

  • @bhanuchowhan6312
    @bhanuchowhan6312 2 ปีที่แล้ว

    Use case

  • @vatsalpatel492
    @vatsalpatel492 4 ปีที่แล้ว

    I am getting "SqlState 42000, Syntax error, permission violation, or other nonspecific error" when I tried to implement @ 12:48

    • @thecodingmentor7701
      @thecodingmentor7701  4 ปีที่แล้ว

      Hi Vatsal, can you copy paste your code here so I can check it?
      Greetings

    • @vatsalpatel492
      @vatsalpatel492 4 ปีที่แล้ว

      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

    • @vatsalpatel492
      @vatsalpatel492 4 ปีที่แล้ว

      Also, 32:36 are LEAF Values, but INNER is mentioned in SQL. A bit confused

    • @thecodingmentor7701
      @thecodingmentor7701  4 ปีที่แล้ว

      @@vatsalpatel492 If you use () instead of {} your code will work

    • @thecodingmentor7701
      @thecodingmentor7701  4 ปีที่แล้ว

      @@vatsalpatel492 Yes you are right, that are LEAF Values, in 34:29 it is corrected

  • @TJ-wo1xt
    @TJ-wo1xt 2 ปีที่แล้ว

    15 is not the number of nodes, its the value of the node right???

    • @thecodingmentor7701
      @thecodingmentor7701  2 ปีที่แล้ว

      About what minute in the video are you talking?

    • @TJ-wo1xt
      @TJ-wo1xt 2 ปีที่แล้ว

      @@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.