Day 13 | LeetCode Learning Journal 🚀 Today I solved Maximum Depth of Binary Tree on LeetCode. This problem helped me understand how to find the maximum depth (height) of a binary tree, which represents the longest path from the root node to a leaf node. 🔑 Key Points: • Uses Depth-First Search (DFS) with recursion • Recursively explore the left and right subtrees • The depth of a tree is calculated as 1 + max(left depth, right depth) • Base case: if the node is null, return 0 • Continue the process until all nodes are visited 🌱 What I Learned: • How recursion works in tree problems • Understanding the concept of height or depth of a binary tree • Practical use of DFS traversal • Improved problem-solving skills in binary tree structures • Strengthened my understanding of recursive algorithms #LeetCode #100DaysOfCode #DSA #BinaryTree #DFS #TreeDepth #Day13 🚀
Max Depth of Binary Tree on LeetCode
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 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 🚀
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 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 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 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 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 77 of 90 – #90DaysDSAChallenge Medium recursion and binary tree challenge today. Visualizing recursion helped a lot. Questions Solved Today: LeetCode 99. – Recover binary search tree(Medium) LeetCode 230. Kth Smallest Element in BST – Maximum Depth of Binary Tree (Medium) Total Questions Solved: 157 ✅ Recursion and trees improve logical thinking. #90DaysDSAChallenge #LeetCode #DSA #DailyCoding #ProblemSolving #CodingJourney #InterviewPrep
To view or add a comment, sign in
-
#100DaysLeetCode Day 35 ✅ Solved LeetCode 523: Continuous Subarray Sum Given an array nums and an integer k, the goal is to check if there exists a subarray of size ≥ 2 whose sum is a multiple of k. 🚀 Approach Used Prefix Sum + HashMap (modulo trick) Key idea: If two prefix sums have the same remainder when divided by k, then the subarray between them is divisible by k Steps: Maintain a running sum Store (sum % k) in a hashmap with index If same remainder appears again → check distance ≥ 2 Also handled edge case: When k == 0, avoid modulo and handle separately ⏱ Complexity Time Complexity: O(n) Space Complexity: O(n) #100DaysLeetCode #Day35 #LeetCode523 #leetcode #cpp #dsa #arrays #hashmap #prefixsum #problemSolving #coding #interviewprep
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