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 🚀
Ayushi kumari’s Post
More Relevant Posts
-
🚀 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 19/100 — LeetCode Challenge (Revision Day) Today I revised Monotonic Stack problems: • Daily Temperatures • Next Greater Element I 🧠 Key Learning: Monotonic stack is extremely useful for solving “next greater/smaller element” problems efficiently in O(n) time. Revisiting these problems helped strengthen pattern recognition and understanding. 📂 Solutions Repository https://lnkd.in/gkFh2mPZ #100DaysOfLeetCode #DSA #LeetCode #CodingChallenge #Revision
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
-
🚀 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
-
🚀 Mastering Binary Search on Answers | LeetCode 410 Today I solved Split Array Largest Sum, a classic problem that strengthens the concept of Binary Search on Answer --- 🔍 Problem Summary Given an array `nums` and an integer `k`, split the array into `k` or fewer subarrays such that the largest subarray sum is minimized. --- 💡 Approach Instead of brute force, I used Binary Search: Search Space: * low = max(nums)` → minimum possible answer * high = sum(nums)` → maximum possible answer * For each `mid`: * Try to divide the array into subarrays where each sum ≤ `mid` * Count how many subarrays (`stud`) are needed * Decision: * If `stud <= k` → try smaller answer (`high = mid - 1`) * Else → increase limit (`low = mid + 1`) 📈 Time Complexity * `O(n * log(sum - max))` 📦 Space Complexity * `O(1)` --- 🔥 Key Takeaway Whenever you see: * “Minimize the maximum” * “Maximum of minimum” 👉 Think Binary Search on Answer! --- #LeetCode #DSA #BinarySearch #CodingInterview #Cpp #ProblemSolving
To view or add a comment, sign in
-
-
Day 23 | LeetCode Learning Journal 🚀 Today I solved Binary Tree Tilt.This problem helped me understand how to combine tree traversal with calculations at each node! 🔑 Key Points: • Used postorder traversal to calculate subtree sums. • Calculated tilt as the absolute difference of left and right subtree sums. • Accumulated tilt for every node in the tree. • Focused on returning subtree sums while updating the result. • Efficient single traversal solution. 🌱 What I Learned: • How to compute values while traversing a tree. • Importance of postorder traversal in such problems. • Better understanding of recursion with return values. • Improved handling of tree-based calculations. #LeetCode #100DaysOfCode #DSA #CodingJourney #BinaryTree #Day23 🚀
To view or add a comment, sign in
-
-
Day 24 Today I solved “Number of 1 Bits” on LeetCode. The task is to count the number of set bits (1s) in the binary representation of a number — also known as Hamming Weight. At first, the straightforward approach is: 👉 Check each bit one by one (using shifts) But I learned a much more efficient trick: 💡 Brian Kernighan’s Algorithm Key Idea: n & (n - 1) removes the rightmost set bit Repeat this until n = 0 Count how many times we do this 👉 Example: n = 11 (1011) 1011 → 1010 1010 → 1000 1000 → 0000 → Count = 3 This gives: Time Complexity: O(k) {k=number of set bits} Space Complexity: O(1) 💡 Key takeaway: Bit manipulation can drastically improve efficiency by operating directly on binary representations. #LeetCode #DSA #LearnInPublic
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
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