1382. Balance a Binary Search Tree || LeetCode POTD || Explained in HINDI

Поділитися
Вставка
  • Опубліковано 24 чер 2024
  • Instagram link:- / reelcoding
    / @reelcoding
    Approach:-
    In-order Traversal:
    Perform an in-order traversal of the BST to obtain a sorted list of values. This is because the in-order traversal of a BST results in a sorted list.
    Balanced BST Creation:
    Use the sorted list to construct a balanced BST. We use a recursive method to choose the middle element of the list or sublist as the root of the subtree. This ensures that the tree remains balanced.
    Helper Methods:
    inOrderTrav : This method performs an in-order traversal of the tree and stores the values in the list inorder.
    createBalanceBST: This method recursively creates a balanced BST from the sorted list inorder.
    Time and Space Complexity
    Time Complexity: O(n)
    The in-order traversal of the BST takes O(n) time.
    Constructing the balanced BST from the sorted list also takes O(n) time.
    Space Complexity: O(n)
    The space complexity is dominated by the space required to store the in-order traversal list, which is O(n).
    Whether you're new to problem-solving or seeking insights into Java programming techniques, this video offers valuable insights into tackling similar challenges effectively.
    Do join with me guys for daily problem solving on LeetCode.
    Please like and subscribe this channel and share among your friends, it helps me to motivate and bring more videos for you guys. ❤️❤️
    Soon, DSA batch (Hinglish) is going to launch on this channel. So, do subscribe so that you will get the notification for all new videos.👍👍🔔🔔.
    Do comment if any doubts left. Thank you 😊
    #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa
    #CodingExplanation #AlgorithmTutorial #JavaProgramming #DataStructures #DynamicProgramming #CodeExplanation #ProgrammingTutorial #AlgorithmExplanation #TechTutorial #LearnToCode #ProblemSolving #ProgrammingConcepts #SoftwareDevelopment #TechEducation #CodingCommunity #CodeBreakdown #ComputerScience
    #JavaTutorial #AlgorithmAnalysis #EducationalContent
    1382. Balance a Binary Search Tree
    Leetcode 1382
    Balance a Binary Search Tree
    Leetcode daily challenge
    Leetcode potd
    1382 Balance a Binary Search Tree
    leetcode potd today solution
    leetcode potd today
    leetcode grind
    leetcode questions for interview
    leetcode series
    leetcode hindi

КОМЕНТАРІ • 10

  • @SupriyaDesai101
    @SupriyaDesai101 Місяць тому +1

    Short video after long long time ❤❤😢

  • @reelcoding
    @reelcoding  Місяць тому

    Code link:- leetcode.com/problems/balance-a-binary-search-tree/solutions/5370767/java-solution-explained-in-hindi/

  • @arihantsinghrana2173
    @arihantsinghrana2173 Місяць тому +1

    Sorted order mein lena jaroori hai kya ?? [3,2,1,null,4,null,null] ye bhi toh valid hai na ?

    • @reelcoding
      @reelcoding  Місяць тому +1

      Haan Kyunki humein yaha balanced BST banana hai toh humein ye make sure karna hogaa ki jo elements hain humaare paas woh 2 equal half mai seperated ho jaise left part mai root se small aur right mai root se greater.
      Aur ek wajah hai middle element ko agar hum root consider karte hain toh ye sure ho jaata hai ki tree balance rahegi as ye baaki kaa part recursion handle karta hai left aur right subtree ko

    • @reelcoding
      @reelcoding  Місяць тому +1

      3,2,1 ye toh yahi wrong ho gaya kyunki iskaa matlab 3 root hai aur left mai 2 aur right mai 1, (BST Condition false) iskaa order 2,1,3 honaa chahyie as 2 root node baaki left mai 1 aur right mai 3

    • @arihantsinghrana2173
      @arihantsinghrana2173 Місяць тому +1

      @@reelcoding mera basically doubt ye ki hume balanced tree banana hai jis mein dono sub tree ka diff less than equal to 1 hona chahiye So does it matter ki node ki values apoint karte tym sorted arraylist se hi karre ? Normal unsorted bhi chalega na kyuki ultimate goal toh balanced tree banana hai right ?

    • @reelcoding
      @reelcoding  Місяць тому +1

      Haan humaara goal balance tree banana hai ye toh sahi hai lekin Binary Search Tree bhi toh hona chahyie iske rules bhi follow hone chahyie naa, warna woh toh normal tree ho jaayega koi saa bhi ….., question mai dekho unne keh rakha hai Balance a Binary Search Tree.
      Toh BST banane ke liye hi humein sorted order ki need ho rahi hai Warna hum nahi karte

    • @arihantsinghrana2173
      @arihantsinghrana2173 Місяць тому +1

      @@reelcoding oooh ohk I totally forgot about binary search tree part 😅
      Thanks for the help broo 👍👍😁