Day 33/100 | #100DaysOfDSA 🌳💻 Today’s problem: Binary Tree Postorder Traversal Postorder follows a simple rule: Left → Right → Root Approach: • Use recursion • Traverse left subtree • Traverse right subtree • Add the root at the end This ensures children are processed before the parent. Time Complexity: O(n) Space Complexity: O(h) (recursion stack) Big takeaway: Tree traversals are just different visiting orders — mastering them builds strong tree intuition. Stacking tree patterns daily. 🚀 #100DaysOfCode #LeetCode #DSA #BinaryTree #Trees #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity #SoftwareEngineer #Consistency #Programmers #TechGrowth
Binary Tree Postorder Traversal with Recursion
More Relevant Posts
-
Day 35/100 | #100DaysOfDSA 🌳💻 Today’s problem: Same Tree The goal is to determine whether two binary trees are identical — meaning they have the same structure and the same node values. Approach: • Use recursion to traverse both trees simultaneously • If both nodes are null → they match • If one node is null and the other isn’t → trees are different • If node values differ → trees are different • Recursively check the left and right subtrees Both trees must match at every node for them to be considered the same. Time Complexity: O(n) Space Complexity: O(h) (recursion stack) Big takeaway: When comparing two trees, traverse them in parallel and validate structure and values at each step. Simple logic, but a great exercise for strengthening recursive tree thinking. One more tree pattern learned. 🚀 #100DaysOfCode #LeetCode #DSA #BinaryTree #Trees #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity #SoftwareEngineer #Consistency #Programmers #TechGrowth
To view or add a comment, sign in
-
-
Day 36/100 | #100DaysOfDSA 🌳💻 Today’s problem: Subtree of Another Tree The task is to determine whether one binary tree is a subtree of another. A subtree must match both the structure and node values of the original tree. Approach: • Traverse the main tree using recursion • At each node, check if the subtree rooted there matches the given subRoot • Use a helper function to compare both trees for structural and value equality • If no match is found, continue checking the left and right subtrees This works by combining two recursive checks: 1️⃣ Search for a potential matching root 2️⃣ Verify if both trees are identical Time Complexity: O(n × m) Space Complexity: O(h) Big takeaway: Complex tree problems often break down into combining simpler tree problems — in this case, tree traversal + same tree comparison. Building stronger tree problem-solving patterns every day. 🚀 #100DaysOfCode #LeetCode #DSA #BinaryTree #Trees #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity #SoftwareEngineer #Consistency #Programmers #TechGrowth
To view or add a comment, sign in
-
-
LeetCode Problem #1920 – Build Array from Permutation Today I solved an interesting array problem that helped me understand indexing and array traversal better. 📌 Problem: Given a 0-indexed array `nums`, build a new array `ans` such that: `ans[i] = nums[nums[i]]` 📌 Approach: * Create a new array `ans` with the same length as `nums` * Traverse the array using a `for` loop * For each index `i`, access the value `nums[i]` * Use that value as an index again to get `nums[nums[i]]` * Store the result in `ans[i]` 📌 Key Concepts Practiced: ✔ Array traversal ✔ Nested indexing ✔ Understanding how values can act as indexes 📌 Time Complexity: O(n) – since we traverse the array only once. 📌 Key Takeaway: Sometimes the value inside an array can also represent an index, and understanding this idea helps solve many array-based problems efficiently. 💡 Learning Note This problem improved my understanding of **index-based operations and array manipulation**, which are fundamental concepts for solving many coding interview questions. #LeetCode #CodingPractice #Java #DSA #Arrays #ProblemSolving
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟑𝟑 – 𝐃𝐒𝐀 𝐉𝐨𝐮𝐫𝐧𝐞𝐲 | 𝐀𝐫𝐫𝐚𝐲𝐬 🚀 Today’s problem focused on generating all unique subsets when the array contains duplicate elements. 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝 • Subsets II 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 • First, sorted the array to group duplicate elements together • Used backtracking to explore subset possibilities • At each step, two choices exist: include the element or skip it • When skipping, moved forward past duplicate elements to avoid repeated subsets This ensures unique subsets are generated. 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬 • Sorting helps handle duplicates effectively • Backtracking explores all combinations systematically • Skipping duplicate elements prevents repeated subsets • Understanding recursion trees helps visualize subset generation 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 • Time: O(n × 2ⁿ) • Space: O(n) (recursion stack) 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 When duplicates exist, generating combinations isn’t the challenge — avoiding repeated ones is. 33 days consistent 🚀 On to Day 34. #DSA #Arrays #Backtracking #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
To view or add a comment, sign in
-
-
Day 34/100 | #100DaysOfDSA 🌳💻 Today’s problem: Diameter of Binary Tree The diameter of a binary tree is the length of the longest path between any two nodes. This path may or may not pass through the root. Approach: • Use DFS recursion to compute the height of each subtree • For every node, calculate leftHeight + rightHeight • Update the maximum diameter during traversal • Return 1 + max(leftHeight, rightHeight) as the height This works because the longest path through any node is formed by combining the heights of its left and right subtrees. Time Complexity: O(n) Space Complexity: O(h) (recursion stack) Big takeaway: Sometimes the best approach is computing one value (height) while updating another (diameter) during recursion. Learning to combine multiple calculations in a single tree traversal is a powerful pattern. Building stronger tree intuition one problem at a time. 🚀 #100DaysOfCode #LeetCode #DSA #BinaryTree #Trees #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity #SoftwareEngineer #Consistency #Programmers #TechGrowth
To view or add a comment, sign in
-
-
🚀 #100DaysOfCode | Day 41 💻 LeetCode – Add to Array-Form of Integer Today I solved a problem focused on array manipulation and digit-by-digit addition. 🔎 Problem: An integer is given in array form, where each element represents a digit. The task is to return the array representation of num + k. 💡 Approach: Instead of converting the array into a number, I simulated manual addition from the last digit, just like we do on paper. ✔ Traverse the array from right to left ✔ Add digits with k and manage the carry ✔ Store the result digits and reverse at the end This approach efficiently handles large inputs and avoids integer overflow. Small problems like this strengthen logic building and problem-solving skills. #LeetCode #DSA #100DaysOfCode #ProblemSolving #Java #CodingJourney #SoftwareDeveloper #TechGrowth
To view or add a comment, sign in
-
-
🚀Solved Validate Stack Sequences by simulating the stack using a simple array instead of relying on built-in stack classes. This helped reduce overhead and kept the operations efficient. Focused on writing clean logic with optimal time complexity. 😊 Result: 💯 Achieved 0 ms runtime beating 100% of submissions, with memory usage around 45.52 MB performing in the top percentile. 💥 #LeetCode #DSA #Java #Coding #ProblemSolving #Preparation #Anurag_University 🚀🚀
To view or add a comment, sign in
-
-
Day 12 – Binary Tree Preorder Traversal 🚀 Continuing my DSA journey with Striver’s A2Z Sheet / LeetCode practice. Today’s problem was about tree traversal, specifically Preorder Traversal, which is one of the most fundamental concepts in Binary Trees. Approach :- Preorder traversal follows: 1️⃣ Visit the root node 2️⃣ Traverse the left subtree 3️⃣ Traverse the right subtree Time Complexity : O(N) Space Complexity : O(N) GitHub Code :- https://lnkd.in/e7skAAvF #LeetCode #DSA #StriverA2Z #CodingJourney #Java #BinaryTree #TreeTraversal #ProblemSolving #CodingPractice #SoftwareEngineering #TechInterviewPrep #Day12#DeveloperJourney
To view or add a comment, sign in
-
-
Day 14 – Binary Tree Postorder Traversal 🚀 Continuing my DSA journey with Striver’s A2Z Sheet / LeetCode practice. Today’s problem focused on Postorder Traversal of a Binary Tree, which is commonly used in problems involving tree deletion, evaluation, and bottom-up processing. 💡 Approach Postorder traversal follows this order: 1️⃣ Traverse the left subtree 2️⃣ Traverse the right subtree 3️⃣ Visit the root node Time Complexity : O(N) Space Complexity : O(N) Github Code : https://lnkd.in/gWW7Tq73 #LeetCode #DSA #StriverA2Z #CodingJourney #Java #BinaryTree #TreeTraversal #ProblemSolving #CodingPractice #SoftwareEngineering #TechInterviewPrep #100DaysOfCode #DeveloperJourney
To view or add a comment, sign in
-
-
🚀 Day 89 - #100DaysOfCode Today I solved a problem on finding the smallest common element between two sorted arrays. 🧩 Problem Given two integer arrays, return the first common element between them. If no common element exists, return -1. 💡 Approach I used a HashSet to efficiently check for common elements. Steps: 1️⃣ Insert all elements of the first array into a HashSet. 2️⃣ Traverse the second array. 3️⃣ Check if the current element exists in the set. 4️⃣ If found, return that element immediately. 5️⃣ If no common element is found, return -1. ⏱ Time & Space Complexity Time Complexity: O(n + m) Space Complexity: O(n) 📌 Key Learning: Using a HashSet helps reduce lookup time to O(1), making the solution efficient #DSA #Java #CodingJourney #LeetCode #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