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 🚀
Binary Tree Tilt Solution via Postorder Traversal
More Relevant Posts
-
🚀 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 40 | LeetCode Learning Journal 🚀 Today I solved Validate Binary Search Tree (BST) using a range-based recursive approach. This problem helped me deeply understand how BST properties apply to the entire tree, not just immediate children! 🔑 Key Points: • Checked whether a binary tree is a valid BST. • Maintained a valid range (min, max) for each node. • Ensured every node follows BST rules globally. • Used recursion to traverse and validate nodes. 🌱 What I Learned: • Importance of passing constraints (min/max) in recursion. • Difference between local vs global validation in trees. • Strengthened understanding of Binary Search Tree properties. • Improved recursive thinking for tree problems. #LeetCode #100DaysOfCode #DSA #CodingJourney #Day40 🚀
To view or add a comment, sign in
-
-
🚀 Day 25/100 — LeetCode Challenge Today's problem: Find Minimum in Rotated Sorted Array 🧠 Concept: Binary Search on Rotated Array 💡 Key Idea: The minimum element represents the pivot point of rotation. By comparing mid with the rightmost element, we can efficiently narrow down the search space. ⚡ Time Complexity: O(log n) 📂 Solutions Repository https://lnkd.in/gkFh2mPZ Continuing to explore how binary search can be adapted for different problem variations. #100DaysOfLeetCode #DSA #LeetCode #CodingChallenge #SoftwareEngineering
To view or add a comment, sign in
-
🚀 LeetCode 378 — Kth Smallest Element in a Sorted Matrix | Solved ✅ Solved this interesting problem using Binary Search on Answer — a powerful pattern! 🔍 Problem Insight: Matrix is sorted row-wise and column-wise, but not flattened. 💡 Approach: • Applied binary search on value range • For each mid, counted elements ≤ mid using matrix properties ⚡ Time Complexity: O(n × log(max - min)) ✨ Key Learning: Not all binary search problems are about indices — sometimes we search in the answer space. 📈 Result: Accepted ✔️ From searching positions → to searching values That’s where problem-solving evolves 🔥 Grateful to Pratyush Narain for the guidance and clear explanations. #LeetCode #DSA #BinarySearch #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 LeetCode 438 — Find All Anagrams in a String | Solved ✅ Solved a Medium-level problem using Sliding Window + Hashing. 🔍 Approach: Maintained a dynamic window and tracked character frequencies to efficiently detect anagrams without re-sorting. ⚡ Complexity: Time: O(n) Space: O(1) (optimized using fixed-size array) 💡 Key Learning: Optimizing from hashmap → array significantly improves performance in character-based problems. Step by step, getting better at pattern recognition 🧠 #LeetCode #DSA #SlidingWindow #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 88/100 – #100DaysOfLeetCode 🚀 🧩 Problem: LeetCode 215 – Kth Largest Element in an Array (Medium) 🧠 Approach: Sort the array and return the element at the ( (n - k) ) index (or simply the k-th largest from the end). 💻 Solution: class Solution: def findKthLargest(self, nums: List[int], k: int) -> int: nums.sort() return nums[-k] ⏱ Time | Space: O(n log n) | O(1) 📌 Key Takeaway: Sorting provides a simple and reliable way to find the k-th largest element, though more optimal approaches like heaps or Quickselect can improve performance. #leetcode #dsa #development #problemSolving #CodingChallenge
To view or add a comment, sign in
-
-
Day 70/100 LeetCode Challenge 🚀 Solved Search in Rotated Sorted Array II using modified binary search. 🔍 Key Learnings: Handling duplicates in rotated arrays is tricky When nums[low] == nums[mid] == nums[high], shrink search space Maintain O(log n) average, but worst case O(n) ⚡ Result: Runtime: 0 ms (Beats 100%) All test cases passed ✅ Consistency > Motivation 💯 #Day70 #LeetCode #BinarySearch #DSA #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 26/100 — LeetCode Challenge Today's problem: Search in Rotated Sorted Array II 🧠 Concept: Binary Search with Edge Cases 💡 Key Idea: Duplicates can make it difficult to identify the sorted half. In such cases, shrink the search space from both ends. ⚡ Time Complexity: O(log n) average, O(n) worst case 📂 Solutions Repository https://lnkd.in/gkFh2mPZ A great example of how edge cases can complicate an otherwise straightforward approach. #100DaysOfLeetCode #DSA #LeetCode #CodingChallenge #SoftwareEngineering
To view or add a comment, sign in
-
31 of #100DaysOfCode Solved LeetCode 442 – Find All Duplicates in an Array using the Cyclic Sort approach 💡 🧠 Key Insight: When elements are in the range 1 to n, we can place each number at its correct index (value → index = value - 1). If a number is already present at its correct position, it reveals a duplicate 🔍 ⚡ What I learned: • In-place array manipulation (O(1) space) • Smart index mapping techniques • Identifying patterns for Cyclic Sort problems #DSA #Cpp #LeetCode #CodingJourney #ProblemSolving #LearnInPublic
To view or add a comment, sign in
-
-
🚀 Day 8/100 — LeetCode Challenge Solved Find Minimum in Rotated Sorted Array At first, it looks tricky because the array is rotated. But the key is to identify which part is sorted. 💡 Approach: 1) If the left half is sorted → the minimum could be at low 2) Otherwise → the minimum lies in the right half 3) Keep narrowing the search space using binary search 👉 Instead of searching for a target, here we’re searching for the minimum element. 🧠 Time Complexity: O(log n) 💾 Space Complexity: O(1) 💡 What I’m realizing: Many problems look different, but they’re just variations of binary search with slight tweaks. Slowly building intuition around it. #LeetCode #DSA #100DaysOfCode #Cpp #BinarySearch #CodingJourney
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