Day 26: Construct Binary Tree from Preorder & Inorder (LeetCode 105) — Amazon Interview Question! 🚀
Автор: Ashwini Kemshetty
Загружено: 2026-02-06
Просмотров: 21
Описание:
🎯 Day 26 of My LeetCode Journey | Construct Binary Tree from Preorder and Inorder Traversal (LeetCode 105)
In this video, I solve LeetCode Problem #105 — Construct Binary Tree from Preorder and Inorder Traversal using JavaScript! This is a frequently asked Amazon interview question 🚨 that tests your understanding of tree traversals and recursive tree construction.
🔗 Problem Link: https://leetcode.com/problems/constru...
📌 PROBLEM SUMMARY:
Given two integer arrays preorder and inorder where:
preorder is the preorder traversal of a binary tree
inorder is the inorder traversal of the same tree
Construct and return the binary tree.
✅ Example 1:
Input: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7]
Output: [3,9,20,null,null,15,7]
✅ Example 2:
Input: preorder = [-1], inorder = [-1]
Output: [-1]
💡 KEY CONCEPTS:
✅ Preorder Traversal (Root → Left → Right): First element is always root
✅ Inorder Traversal (Left → Root → Right): Elements before root are in left subtree
✅ HashMap for fast index lookup
✅ Recursive tree construction
✅ Divide and conquer strategy
📊 COMPLEXITY:
• Time: O(n) - visit each node once
• Space: O(n) - recursion stack
🎓 DIFFICULTY: Medium
🏷️ TOPICS: Array, Divide and Conquer, Tree, Binary Tree
🏢 ASKED AT: Amazon, Microsoft, Facebook, Bloomberg
🔥 WHY THIS MATTERS:
This is a classic tree reconstruction problem that appears in Amazon interviews frequently. Understanding how preorder and inorder traversals work together is crucial for many tree-related problems!
💻 JAVASCRIPT SOLUTION:
I'll walk you through the complete JavaScript implementation with detailed explanations!
🔔 SUBSCRIBE for daily LeetCode solutions in JavaScript!
👍 LIKE if this helped you prepare for interviews!
💬 COMMENT your approach or questions below!
📚 MY LEETCODE JOURNEY PLAYLIST:
• Leetcode
🤝 CONNECT WITH ME:
• GitHub: https://github.com/ashwinikemshetty
• LinkedIn: / ashwinikemshetty
#LeetCode #ConstructBinaryTree #LeetCode105 #Day26 #JavaScript #AmazonInterview #TreeTraversal #PreorderInorder #CodingInterview #DSA #Algorithms #100DaysOfCode #100DaysChallenge
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: