Day 10/30 — DSA Challenge 🚀 Problem: Construct Binary Tree from Inorder and Postorder Traversal Topic: Tree + Recursion + Hashing Difficulty: Medium Approach: Used postorder to identify root node (last element) Used inorder to split tree into left and right subtrees Stored inorder indices in a HashMap for fast lookup Built tree recursively (right subtree first, then left) Mistake / Challenge: Initially confused about traversal order Made mistake by building left subtree first instead of right Fix: Understood that postorder processes (Left → Right → Root) So while constructing → build Right first, then Left Key Learning: Preorder → Root first Postorder → Root last Always align recursion order with traversal type Time Taken: 50 minutes Consistency check ✅ See you on Day 11. GitHub Repo: https://lnkd.in/gHW9vKUf #DSA #LeetCode #Java #Trees #Recursion #LearningInPublic
Construct Binary Tree from Inorder and Postorder Traversal
More Relevant Posts
-
Day 9/30 — DSA Challenge 🚀 Problem: Construct Binary Tree from Preorder and Inorder Traversal Topic: Tree + Recursion + Hashing Difficulty: Medium Approach: Used preorder to identify root node Used inorder to divide left and right subtrees Stored inorder indices in a HashMap for O(1) lookup Recursively built left and right subtrees Mistake / Challenge: Initially struggled to understand how preorder and inorder work together Got confused in managing indices for subtree boundaries Fix: Used a pointer for preorder traversal Used HashMap to quickly find root index in inorder Carefully handled left and right subtree ranges Key Learning: Preorder → gives root Inorder → gives structure (left/right split) Combining both helps reconstruct the tree Time Taken: 1 hour Consistency check ✅ See you on Day 10. GitHub Repo: https://lnkd.in/gHW9vKUf #DSA #LeetCode #Java #Trees #Recursion #LearningInPublic
To view or add a comment, sign in
-
-
Day 5/30 — DSA Challenge 🚀 Problem: Path Sum II Topic: Tree + Recursion + Backtracking Difficulty: Medium Approach: Used DFS to explore all root-to-leaf paths Maintained a list to store the current path Tracked running sum while traversing At leaf node → if sum equals target, added path to result Mistake / Challenge: Initially forgot to backtrack (removing last element from path) This caused incorrect paths to be stored Fix: Used backtracking → removed last node after recursive calls Ensured correct path formation Key Learning: Whenever you’re storing paths → think Backtracking Always clean up (undo choice) after recursion Time Taken: 45 minutes Consistency check ✅ See you on Day 6. GitHub Repo: https://lnkd.in/gHW9vKUf #DSA #LeetCode #Java #Trees #Backtracking #LearningInPublic
To view or add a comment, sign in
-
-
Day 4/30 — DSA Challenge 🚀 Problem: Path Sum Topic: Tree + Recursion Difficulty: Easy Approach: Used DFS to traverse all root-to-leaf paths Kept a running sum while traversing At leaf node → checked if sum equals target Mistake / Challenge: Initially confused about when to check the sum Tried checking at every node instead of only at leaf nodes Fix: Checked condition only when reaching a leaf node Simplified recursion by passing current sum Key Learning: In tree problems, clearly identify the base condition (leaf node here) Avoid unnecessary checks at intermediate nodes Time Taken: 30 minutes Consistency check ✅ See you on Day 5. GitHub Repo: https://lnkd.in/gHW9vKUf #DSA #LeetCode #Java #Trees #Recursion #LearningInPublic
To view or add a comment, sign in
-
-
Day 8/30 — DSA Challenge 🚀 Problem: Search a 2D Matrix II Topic: Matrix + Binary Search Pattern Difficulty: Medium Approach: Started from top-right corner of the matrix If current element == target → return true If current element < target → move down If current element > target → move left Mistake / Challenge: Initially tried applying binary search like previous problem (LeetCode 74) Realized matrix is not globally sorted, so that approach fails Fix: Used optimal “staircase search” approach Reduced time complexity efficiently Key Learning: Not all sorted matrices can be treated as 1D arrays Recognize pattern: row-wise + column-wise sorted → use pointer approach Time Taken: 45 minutes Consistency check ✅ See you on Day 9. GitHub Repo: https://lnkd.in/gHW9vKUf #DSA #LeetCode #Java #Matrix #BinarySearch #LearningInPublic
To view or add a comment, sign in
-
-
Day 2/30 — DSA Challenge 🚀 Problem: Lowest Common Ancestor of Deepest Leaves Topic: Tree + DFS Difficulty: Medium Approach: Used DFS to calculate depth of left and right subtrees At each node, compared depths: If equal → current node is LCA Else → return deeper subtree result Mistake / Challenge: Initially overcomplicated thinking about storing all deepest nodes Realized we don’t need to track nodes explicitly, depth comparison is enough Fix: Returned a Pair (node, depth) from recursion Handled everything in one DFS traversal Key Learning: Tree problems often look complex but can be simplified with recursion Focus on what needs to be returned from each call Time Taken: 60 minutes Consistency check ✅ See you on Day 3. GitHub Repo: https://lnkd.in/g87geK_g #DSA #LeetCode #Java #Trees #Recursion #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Day 45/60 – DSA Challenge Today’s problem was about searching in a Rotated Sorted Array using Binary Search 🔍 🔍 Problem Solved: Given a rotated sorted array, efficiently find the index of a target element. 🧠 Approach I Used: Instead of directly applying binary search, I broke the problem into two steps: 1️⃣ Find the pivot (rotation point) using binary search 2️⃣ Apply binary search on the correct half of the array Left half → sorted from start to pivot-1 Right half → sorted from pivot to end ⚡ Key Insight: By identifying the pivot, the problem becomes two simple binary searches Careful boundary checks (like target >= nums[0]) ensure we search in the correct half Handling edge cases (like pivot at index 0) is crucial for correctness 📈 Complexity: Time: O(log n) Space: O(1) 🎯 What I Learned: Complex problems can often be simplified by breaking them into smaller parts Binary Search is not just about searching—it’s about understanding structure Boundary conditions can make or break your solution Debugging edge cases today made the concept even clearer 💡 #Day45 #DSAChallenge #BinarySearch #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
DSA Day 11 – Prefix Sum + HashMap Pattern Today I solved the “Subarray Sum Equals K” problem on LeetCode. Problem: Given an array and an integer k, find the total number of subarrays whose sum equals k. Approach Used: -> Used Prefix Sum to keep track of cumulative sum -> Used HashMap to store frequency of prefix sums -> At each step, checked if (currentSum - k) exists in map -> If yes → added its frequency to count Time Complexity: -> O(n) Space Complexity: -> O(n) Key Learning: -> Prefix Sum helps convert subarray problems into simple calculations -> HashMap allows constant time lookup for previous sums -> Instead of checking all subarrays (O(n²)), we optimize to O(n) What I Realized: Earlier I used brute force for subarrays, but today I understood how prefix sum + hashmap eliminates nested loops completely. This pattern is powerful for many subarray problems. Thanks to Pulkit Aggarwal sir for guiding me in DSA and helping me understand problem-solving patterns. Consistency is turning into real problem-solving ability. #DSA #LeetCode #Java #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
💻 Day 80 – DSA Practice (Binary Trees) Today’s challenge: 👉 Find all root-to-leaf paths where the sum equals a given target. 🔹 Approach: Use Depth-First Search (DFS) Track the current path and remaining sum When reaching a leaf node, check if the sum matches 💡 Key Concepts: Recursion + Backtracking Tree traversal (DFS) Efficient sum handling ⚡ Insight: Reducing the target sum at each step makes the solution cleaner and avoids recalculating sums. #DSA #BinaryTree #Java #CodingJourney #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
Day 68 of My DSA Journey Today’s problem: Symmetric Tree 🌳 Problem Statement Given a binary tree, check whether it is a mirror of itself (symmetric around its center). Key Insight A tree is symmetric if: Left subtree is a mirror of the right subtree Compare nodes in a cross manner: Left → Left with Right → Right Left → Right with Right → Left 🧠 Approach Use recursion to compare two nodes at a time Base cases: If both nodes are null → symmetric If one is null → not symmetric Check: Values are equal Outer and inner pairs match ⚡ Complexity Time: O(n) Space: O(h) (recursion stack) ✨ What I Learned This problem improved my understanding of recursion and how to think in terms of mirror structures instead of normal traversal. Consistency is the key 🔑 — one problem at a time! #DSA #Java #BinaryTree #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 76/100 Completed ✅ 🚀 Solved LeetCode – Search a 2D Matrix (Java) ⚡ Implemented an optimized binary search approach by treating the 2D matrix as a flattened sorted array. Converted 1D index into 2D coordinates (row = mid / m, col = mid % m) to efficiently locate the target in O(log(m × n)) time. 🧠 Key Learnings: • Applying binary search on a 2D matrix • Converting 1D index to 2D (row & column mapping) • Reducing time complexity from O(m × n) → O(log(m × n)) • Importance of problem observation (matrix behaves like sorted array) 💯 This problem strengthened my understanding of binary search variations and how to apply it beyond simple 1D arrays. 🔗 Profile: https://lnkd.in/gaJmKdrA #leetcode #datastructures #algorithms #java #matrix #binarysearch #arrays #optimization #problemSolving #100DaysOfCode 🚀
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development