Day 15 | LeetCode Learning Journal 🚀 Today I solved Same Tree (LeetCode 100). This problem helped me understand how to compare two binary trees and check whether they are structurally identical and have the same node values. 🔑 Key Points: • Uses Depth-First Search (DFS) with recursion • Compare corresponding nodes of both trees • Check if both nodes are NULL (trees match at that point) • If values differ or structure differs → trees are not identical • Continue recursively for left and right subtrees 🌱 What I Learned: • How recursion works with binary trees • Comparing two trees node by node • Handling base cases in recursive tree problems • Strengthened my understanding of DFS in trees • Improved logical thinking for tree comparison problems #LeetCode #100DaysOfCode #DSA #BinaryTree #DFS #SameTree #Day15 🚀
LeetCode 100: Same Tree Problem Solution
More Relevant Posts
-
Day 17 | LeetCode Learning Journal 🚀 Today I solved Binary Tree Maximum Path Sum. This problem helped me understand how to find the maximum path sum in a binary tree, where a path can start and end at any node. 🔑 Key Points: • Uses Depth-First Search (DFS) with recursion. • Calculate the maximum contribution from left and right subtrees. • Ignore negative path sums to maximize the result. • Update the global maximum path sum at each node. • Continue traversal until all nodes are processed. 🌱 What I Learned: • How to handle complex recursion in binary trees • Calculating path sums while traversing the tree • Managing global variables to track the maximum result • Improved understanding of DFS in tree problems • Strengthened my problem-solving skills for advanced binary tree questions #LeetCode #100DaysOfCode #DSA #BinaryTree #DFS #MaximumPathSum #Day17 🚀
To view or add a comment, sign in
-
-
🚀 Day 21/50 – LeetCode Challenge 🧩 Problem #100 – Same Tree Today’s problem focused on comparing two binary trees — a great exercise in recursion and tree traversal. 📌 Problem Summary: Given the roots of two binary trees, determine whether they are identical. Two trees are considered the same if: ✔ They have the same structure ✔ Corresponding nodes have the same values 🔍 Approach Used ✔ Used recursion to compare both trees node by node ✔ Checked: If both nodes are null → valid If one is null → not same If values differ → not same ✔ Recursively compared left and right subtrees ⏱ Time Complexity: O(n) 📦 Space Complexity: O(h) (height of tree) 💡 Key Learning ✔ Understanding tree traversal ✔ Applying recursion effectively ✔ Comparing structures along with values ✔ Strengthening binary tree fundamentals A simple problem that builds strong foundation in tree-based questions. Consistency is the key to mastery 🚀 🔗 Problem Link: https://lnkd.in/gg45uzAs #50DaysOfLeetCode #LeetCode #DSA #BinaryTree #Recursion #ProblemSolving #CodingJourney #FutureAIEngineer #Consistency
To view or add a comment, sign in
-
-
Day 34 | LeetCode Learning Journal 🚀 Today’s focus was Problem 104: Maximum Depth of Binary Tree. The core idea here is the elegance of Recursion. Instead of thinking about the entire tree at once, the concept is to break it down: the height of any node is simply 1 + the maximum height of its children. It’s fascinating how the code "drills down" to the leaf nodes (the base case) and then builds the answer back up as the recursion unwinds. This problem is a perfect example of how a Bottom-Up approach works—solving the smallest sub-problems first to find the solution for the root. 34 days done — and my intuition for recursive thinking is getting much sharper. Understanding how memory stacks and base cases interact is key to mastering more complex tree and graph algorithms. #LeetCode #100DaysOfCode #Recursion #BinaryTree #LogicBuilding #DSA #CPlusPlus #CodingJourney #ProblemSolving #DepthFirstSearch
To view or add a comment, sign in
-
-
🚀 Day 22/50 – LeetCode Challenge 🧩 Problem: Symmetric Tree Today’s problem focused on checking whether a binary tree is a mirror of itself — a great exercise in recursion and tree traversal. 📌 Problem Summary: Given the root of a binary tree, determine whether it is symmetric around its center. A tree is symmetric if the left subtree is a mirror reflection of the right subtree. 🔍 Approach Used ✔ Used recursion to compare nodes in a mirrored way ✔ Checked: If both nodes are null → symmetric If one is null → not symmetric If values are equal → continue checking ✔ Compared: left subtree of one side with right subtree of the other right subtree with left subtree ⏱ Time Complexity: O(n) 📦 Space Complexity: O(h) 💡 Key Learning ✔ Understanding mirror structure in trees ✔ Applying recursion with multiple conditions ✔ Importance of checking both sides (left ↔ right and right ↔ left) ✔ Strengthening binary tree problem-solving This problem showed how small logical mistakes (like missing one recursive check) can affect correctness — a great learning experience. Consistency builds mastery 🚀 🔗 Problem Link: https://lnkd.in/gSHvYR2S #50DaysOfLeetCode #LeetCode #DSA #BinaryTree #Recursion #ProblemSolving #CodingJourney #FutureAIEngineer #Consistency
To view or add a comment, sign in
-
-
🚀 Day 20 | LeetCode Learning Journal. Today I solved Minimum Depth of Binary Tree. This problem looked simple at first, but it taught me an important edge case in binary trees! 🔑 Key Points: • Used recursion (DFS) to calculate depth. • Handled cases where one subtree is missing. • Learned that we must not take min of NULL paths directly. • Carefully checked leaf nodes (both left & right NULL). • Returned correct depth by considering valid paths only. 🌱 What I Learned: • Difference between minimum depth and general depth calculation • Importance of handling edge cases in trees • How NULL nodes can affect recursion results • Improved understanding of binary tree traversal logic #LeetCode #100DaysOfCode #DSA #BinaryTree #Recursion #DFS #Day20 🚀
To view or add a comment, sign in
-
-
Day 16 | LeetCode Learning Journal 🚀 Today I solved Binary Tree Right Side View . This problem helped me understand how to identify the nodes visible when looking at a binary tree from the right side. 🔑 Key Points: • Uses Breadth-First Search (BFS) with a queue. • Traverse the binary tree level by level. • At each level, capture the last node visited. • The last node of every level represents the right side view. • Continue until all levels of the tree are processed. 🌱 What I Learned: • How to apply level order traversal in binary trees • Identifying the rightmost node at each level • Better understanding of queue-based traversal • Strengthened my binary tree traversal concepts • Improved problem-solving skills in tree-based problems #LeetCode #100DaysOfCode #DSA #BinaryTree #BFS #RightSideView #Day16 🚀
To view or add a comment, sign in
-
-
Day 36 | LeetCode Learning Journal 🚀 Leveling up today with a Hard challenge: Problem 124: Binary Tree Maximum Path Sum. This problem was a masterclass in recursive depth. Unlike many tree problems where you just pass data upward, this one required tracking a "global maximum" while simultaneously deciding which branch offers the best path to contribute to the parent node. Key insights from today: Post-order Traversal: Understanding that we need information from both subtrees before we can make a decision at the current node. The "Max" Logic: Learning to ignore negative path sums by using max(0, ...) was the "aha!" moment that made everything click. Global vs. Local: Differentiating between the path that can be extended to a parent and the path that ends at the current node. #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #CPlusPlus #DSA #BinaryTree #Recursion #Algorithm #HardProblem
To view or add a comment, sign in
-
-
🚀 Day 18/100 — LeetCode Challenge (Revision Day) Today I revised Stack-based problems: • Valid Parentheses • Min Stack 🧠 Key Learning: Stack is extremely useful for handling nested structures and designing efficient data structures with constant-time operations. Revisiting these problems helped reinforce core concepts and design thinking. 📂 Solutions Repository https://lnkd.in/gkFh2mPZ #100DaysOfLeetCode #DSA #LeetCode #CodingChallenge #Revision
To view or add a comment, sign in
-
Day 7 🚀 Solved: Balanced Binary Tree (LeetCode 110) This problem builds on recursion and tree depth. A tree is balanced if the height difference between left and right subtrees is at most 1 for every node. 💡 My approaches: 🔹 Approach 1 (Brute Force): For every node, calculate left and right subtree heights Check the difference and recurse further 🔹 Approach 2 (Optimal – Postorder DFS): Compute height and balance together in one traversal Avoid recomputing subtree heights 💡 Key learning: Instead of solving subproblems separately, combine them in a single DFS to optimize performance. ⏱️ Time Complexity: Brute Force → O(n²) Optimal → O(n) 🔗 GitHub: https://lnkd.in/gVdJeg2a #DSA #LeetCode #Coding
To view or add a comment, sign in
-
🚀 Day 22/100 — LeetCode Challenge Today's problem: First Bad Version 🧠 Concept: Binary Search on Answer 💡 Key Idea: Instead of searching for a value, use binary search to find the point where a condition changes (from good to bad). ⚡ Time Complexity: O(log n) 📂 Solutions Repository https://lnkd.in/gkFh2mPZ Learning how binary search can be applied beyond just searching in arrays. #100DaysOfLeetCode #DSA #LeetCode #CodingChallenge #SoftwareEngineering
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