Construct Binary Tree from Preorder and Postorder Traversal | Leetcode 889 | codestorywithMIK
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
Similar Questions :
Construct Binary Tree from Preorder and Inorder Traversal : • Construct Binary Tree From Preorder A...
Construct Binary Tree from Inorder and Postorder Traversal : • Construct Binary Tree from Inorder an...
Hi Everyone, this is the 57th video of our Playlist "Binary Tree : Popular Interview Problems".
Now we will be solving a good Binary Tree problem - Construct Binary Tree from Preorder and Postorder Traversal | Brute Force | Optimised | Leetcode 889 | codestorywithMIK
Problem Name : Construct Binary Tree from Preorder and Postorder Traversal | Brute Force | Optimised | Leetcode 889 | codestorywithMIK
Company Tags : Will update later
My solutions on Github(C++ & JAVA) - https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Tree/Construct Binary Tree from Preorder and Postorder Traversal.cpp
Leetcode Link : https://leetcode.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal
My DP Concepts Playlist : • Roadmap for DP | How to Start DP ? | ...
My Graph Concepts Playlist : • Graph Concepts & Qns - 1 : Graph will...
My Segment Tree Concepts Playlist : • Segment Tree | Introduction | Basics ...
My Recursion Concepts Playlist : • Introduction | Recursion Concepts And...
Trie Playlist - • Word Search II (Google, Amazon, Meta,...
Difference Array Technique: Concepts & Qns : • Introduction | What | How | Differenc...
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK
Subscribe to my channel : / @codestorywithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Video Summary :
Approach 1 (Brute Force)
This approach recursively reconstructs the binary tree by identifying the root from the preorder array. It then finds the left subtree's root in the postorder array by iterating through it. The left and right subtrees are built using the identified segments of the preorder and postorder arrays. This results in an O(n^2) time complexity due to repeated searches in the postorder array.
Approach 2 (Using Map for Optimization)
This approach improves efficiency by using a hashmap to store indices of postorder values. Instead of iterating through the postorder array, it directly finds the left subtree’s root index in O(1) time. This significantly reduces redundant searches, making the algorithm run in O(n) time. The recursive structure remains the same, but the use of a hashmap optimizes subtree identification.
✨ Timelines✨
00:00 - Introduction
0:16 - Motivation
00:43 - Problem Explanation
2:57 - Similar Problems
3:21 - Thought Process Approach-1
22:17 - Story To Code
30:25 - Time & Space Complexity
31:18 - Coding Approach-1
35:59 - Optimisation Approach-2
38:01 - Coding Approach-2
#MIK #mik #Mik
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #coding #programming #100daysofcode #developers #techjobs #datastructures #algorithms #webdevelopment #softwareengineering #computerscience #pythoncoding #codinglife #coderlife #javascript #datascience #leetcode #leetcodesolutions #leetcodedailychallenge #codinginterview #interviewprep #technicalinterview #interviewtips #interviewquestions #codingchallenges #interviewready #dsa #hindi #india #hindicoding #hindiprogramming #hindiexplanation #hindidevelopers #hinditech #hindilearning #helpajobseeker #jobseekers #jobsearchtips #careergoals #careerdevelopment #jobhunt #jobinterview #github #designthinking #learningtogether #growthmindset #digitalcontent #techcontent #socialmediagrowth #contentcreation #instagramreels #videomarketing #codestorywithmik #codestorywithmick #codestorywithmikc #codestorywitmik #codestorywthmik #codstorywithmik #codestorywihmik #codestorywithmiik #codeistorywithmik #codestorywithmk #codestorywitmick #codestorymik #codestorwithmik