Day 56 : Crushing Binary Trees on LeetCode 💡 Today’s live practical session in Alpha Plus 7.0 We focused on some of the most challenging Binary Tree questions on LeetCode, breaking down the logic behind them. What I practiced today: ✅ Tree Diameter: understand the logic to calculate the absolute longest path between any two nodes in the entire tree. ✅ Maximum Path Sum: Tackled a famous "Hard" level problem! Figured out how to find the path with the highest possible sum, even if it doesn't pass through the root. ✅ Target Deletion: Wrote the recursive code to systematically find and delete leaf nodes that match a specific target value. #BinaryTree #LeetCode #ProblemSolving #DSA #Java #SoftwareEngineering #100DaysOfCode #ApnaCollege
Crushing Binary Trees on LeetCode: Diameter, Max Path Sum, Target Deletion
More Relevant Posts
-
100 Days of Code Day - 24 🔁 Swap Nodes in Pairs – LeetCode Problem Solved a classic Linked List problem today! 💡 👉 Given a linked list, swap every two adjacent nodes without modifying values — only changing the links. ✅ Example: Input: [1,2,3,4] Output: [2,1,4,3] 💭 Approach: Used a dummy node and pointer manipulation to efficiently swap nodes in O(n) time and O(1) space. 📌 Key Learning: Understanding pointer handling is crucial for mastering Linked Lists. #LeetCode #Java #DSA #LinkedList #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
💡 Day 54 of LeetCode Problem Solved! 🔧 🌟 560. Subarray Sum Equals K 🌟 🔗 Solution Code: https://lnkd.in/g5VwiFKd 🧠 Approach: Prefix Sum & Hash Map Store cumulative sums in a Map Check for (current_sum - k) to find matching subarrays in one pass ⚡ Key Learning: Mastering the Prefix Sum + HashMap pattern is a game-changer for transforming $O(n^2)$ subarray problems into efficient $O(n)$ solutions. ⏱️ Complexity: Time: O(n) Space: O(n) #LeetCode #Java #DSA #ProblemSolving #Consistency #100DaysOfCode #CodingJourney #PrefixSum #DataStructures
To view or add a comment, sign in
-
-
💻 Day 35 of #LeetCode Journey 🔥 Solved: 19. Remove Nth Node From End of List Today’s problem was all about mastering Linked Lists and understanding the power of the Two Pointer technique. 🔍 Key Idea: Instead of calculating the length, I used a smart approach with fast and slow pointers. Move the fast pointer n steps ahead Then move both pointers together This helps locate the node to remove in a single pass ⚡ Why this approach? Efficient: O(n) time complexity No extra space required Clean and optimal solution 🧠 What I learned: Using a dummy node simplifies edge cases (like removing the head) Two-pointer technique is very powerful in linked list problems 📌 Problem Link: https://lnkd.in/gxXDR-YV #Java #DataStructures #LinkedList #CodingJourney #100DaysOfCode #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 69 — LeetCode Practice 🚀 Today’s focus was on string manipulation and careful indexing. ✅ Problem solved today: 🔹 Find Common Characters 💡 Key learnings from today: • Understood how to find common characters across multiple strings • Learned the importance of character frequency counting • Practiced handling nested loops efficiently • Realized how small mistakes in indexing can affect the entire logic • Improved attention to detail while working with strings Initially, I made a mistake by using the wrong variable inside charAt(). This caused incorrect indexing, which can either lead to wrong output or even StringIndexOutOfBoundsException. After fixing it, the logic worked perfectly by correctly comparing characters and tracking their minimum frequency across all words. This problem reinforced an important lesson: Sometimes errors are not in logic — but in small details like indexing and variable usage. Accuracy matters as much as logic. Step by step, getting better 💪 On to Day 70 🚀 #Day69 #DSA #LeetCode #ProblemSolving #Java #CodingJourney #Consistency #FutureEngineer
To view or add a comment, sign in
-
-
🚀 LeetCode Challenge 3/50 💡 Approach: Two Pointer (In-Place) The straightforward way uses an extra array — but the problem specifically says no copying! So I used the Two Pointer technique to solve it in-place with a single pass. 🔍 Key Insight: → Use a 'left' pointer to track where the next non-zero element belongs → Traverse with 'right' pointer — place non-zeros at left, then increment → Fill remaining positions with 0s at the end 📈 Complexity: ✅ Time: O(n) — single pass ✅ Space: O(1) — no extra array, truly in-place Sometimes the constraint IS the optimization. Working within limits pushes us to think smarter! 🧠 #LeetCode #DSA #TwoPointer #Java #ADA #PBL2 #LeetCodeChallenge #Day3of50 #CodingJourney #ComputerEngineering #AlgorithmDesign #MoveZeroes
To view or add a comment, sign in
-
-
🚀 Day 71/100 – LeetCode Challenge Solved: Remove Duplicates from Sorted List II (Medium) Today’s problem was a great test of Linked List manipulation and handling edge cases efficiently. 🔍 Key Insight: Since the list is sorted, duplicates appear consecutively. Instead of keeping one copy, the challenge is to remove all nodes with duplicate values, leaving only distinct elements. 💡 Approach: Used a dummy node to handle edge cases Applied two-pointer technique (prev & current) Skipped entire duplicate sequences in one pass ⚡ Result: Runtime: 0 ms (Beats 100%) Space Complexity: O(1) 🎯 Key Learning: Handling duplicates in linked lists requires careful pointer updates — especially when the head itself is part of duplicates. Consistency is key 🔥 #Day71 #LeetCode #100DaysOfCode #Java #DataStructures #LinkedList #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 81 of #LeetCode Journey Solved: Subarray Sums Divisible by K Today’s problem helped me understand the power of Prefix Sum + HashMap optimization. 💡 Key Learning: Instead of checking all subarrays (O(n²)), we can use modulo + frequency map to reduce it to O(n). If two prefix sums have the same remainder, the subarray between them is divisible by K. 🧠 Concepts used: Prefix Sum Modulo Arithmetic HashMap (Frequency Count) ✅ Result: Accepted ✔️ Consistency is building confidence day by day 💪 #Day81 #DSA #Java #LeetCode #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 101 - LeetCode Journey Solved LeetCode 856: Score of Parentheses ✅ Looks tricky at first, but turns out to be a neat pattern problem. Instead of using a stack, used depth tracking + bit manipulation to calculate score efficiently. Core idea: Every "()" contributes 2^depth So just track depth and add score at the right moment. Key learnings: • Understanding pattern inside parentheses • Using depth instead of extra space • Bit manipulation for optimization ⚡ • Clean O(n) solution without stack ✅ All test cases passed ⚡ O(n) time | O(1) space Simple logic, powerful result 💡 #LeetCode #DSA #Stack #BitManipulation #Java #CodingJourney #ProblemSolving #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 48 of My #LeetCode Journey Today’s problem: 2615. Sum of Distances 💡 Key Idea: Instead of calculating distances between equal elements using brute force (O(n²)), I used: HashMap to group indices of same values Prefix Sum to efficiently compute distances This reduced the complexity to O(n) 🔥 🧠 What I Learned: How prefix sums can optimize distance calculations Efficient handling of repeated elements Writing clean and optimized code using Java ⚡ Approach: Store indices of each number Use prefix sums to calculate left & right distances Combine both to get final answer 📈 Time Complexity: O(n) 📦 Space Complexity: O(n) Consistency is key. Small progress every day leads to big results 💪 #Day48 #Java #FullStackDeveloper #CodingJourney #100DaysOfCode #DSA #LeetCode
To view or add a comment, sign in
-
LeetCode Day 45 Today I solved the Contains Duplicate problem. Problem Insight: Given an integer array, we need to check whether any element appears more than once. Approach: Sorted the array first Compared adjacent elements If two consecutive elements are equal → duplicate found Key Learning: Sorting helps bring duplicates together, making it easy to detect them with a single pass. Complexity: Time: O(n log n) Space: O(1) Consistency builds confidence — Day 45 done! #LeetCode #Java #DSA #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