🚀 Day 49 of #100DaysOfCode Solved LeetCode Problem #1339 – Maximum Product of Splitted Binary Tree 🌳 This problem focused on splitting a binary tree into two subtrees such that the product of their sums is maximized. It required a two-pass DFS strategy first to compute the total sum, and second to evaluate every possible split efficiently. Key Learnings: -> Used DFS to calculate subtree sums -> Explored every edge as a potential split point -> Tracked the maximum product using global state -> Applied modulo arithmetic to handle large results Language Used: Java -> Runtime: 7 ms (Beats 47.86%) -> Memory: 60.07 MB Deepening tree recursion skills and optimization thinking, one problem at a time 🚀🌲 #LeetCode #BinaryTree #DFS #Java #ProblemSolving #DSA #100DaysOfCode
Maximizing Binary Tree Product with DFS Strategy
More Relevant Posts
-
🚀 Day 48 of #100DaysOfCode Solved LeetCode Problem #1161 – Maximum Level Sum of a Binary Tree 🌳 This problem focused on analyzing a binary tree level by level to find which level gives the maximum sum of node values. A clean use-case for Breadth-First Search (BFS) with queues. Key Learnings: -> Applied level-order traversal (BFS) using a queue -> Calculated the sum of each level independently -> Tracked the level index with the maximum sum -> Reinforced tree traversal patterns and queue usage Language Used: Java -> Runtime: 9 ms (Beats 64.42%) -> Memory: 49.44 MB Another solid step forward in mastering tree-based problems 🚀🌲 #LeetCode #BinaryTree #BFS #Java #ProblemSolving #DSA #100DaysOfCode
To view or add a comment, sign in
-
-
Day 47/50 of #50DaysOfDSA 🚀 Today’s focus was on string manipulation and stack-based logic with LeetCode 1614 — Maximum Nesting Depth of the Parentheses. The Problem: Given a valid parentheses string, the goal is to find the maximum nesting depth. My Approach: Instead of using an actual stack data structure, I used a simple counter to track the current depth: Increment the counter when encountering ( Decrement when encountering ) Track the maximum value the counter reaches during the iteration. The Result: ✅ Runtime: 0 ms (Beats 100.00% of Java submissions!) ✅ Complexity: O(n) time and O(1) space. It’s satisfying to see how a simple linear scan can be so performant. Almost at the finish line! 🏁 #DSA #CodingChallenge #Java #LeetCode #ProblemSolving #SoftwareEngineering #Day47
To view or add a comment, sign in
-
-
🚀 Day 69 of #100DaysOfCode Solved LeetCode Problem #3650 – Minimum Cost Path with Edge Reversals ✅ This problem was a great application of graph algorithms, where the goal was to minimize cost by smartly handling edge directions and reversals. Modeling the problem correctly made all the difference. Key Learnings: -> Converting edge reversals into weighted edges -> Using graph representation effectively -> Applying Dijkstra’s algorithm for shortest path -> Thinking beyond direct edges to optimize cost Language Used: Java -> Runtime: 75 ms (Beats 85.02%) -> Memory: 275.60 MB (Beats 39.27%) Consistency > Motivation 🚀 Onwards to Day 68 💪 #LeetCode #GraphAlgorithms #Dijkstra #Java #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day28 - LeetCode Journey Solved LeetCode 383: Ransom Note in Java ✅ This problem was a great example of how frequency counting can simplify string-based logic. The task was to check whether a ransom note can be constructed using characters from a magazine, with each character usable only once. Using a fixed-size frequency array made the solution clean and efficient. First counting all characters in the magazine and then consuming them while checking the ransom note felt very intuitive. The moment any required character ran out, we could immediately return false. Simple logic, strong impact. What stood out here was how important it is to choose the right data structure. A small optimization like using an array instead of a map makes the solution faster and more memory-efficient. Key takeaways: • Effective use of frequency arrays • Strong practice of string traversal • Early termination for better performance • Writing optimized and readable code ✅ Accepted successfully ✅ 1 ms runtime with top performance Problems like these quietly sharpen your fundamentals. Staying consistent, one problem at a time 💪 #LeetCode #Java #DSA #Strings #ProblemSolving #Algorithms #CodingJourney #InterviewPreparation #DailyPractice #Consistency
To view or add a comment, sign in
-
-
📅 Day 60 of #100DaysOfLeetCode 🌳 Problem: 1161. Maximum Level Sum of a Binary Tree 🟡 Difficulty: Medium 🧠 Problem Summary Given a binary tree, each level has a sum of its node values. The task is to find the smallest level number whose node sum is maximum. 💡 Approach (BFS / Level Order Traversal) Use a queue to traverse the tree level by level For each level: Calculate the sum of all nodes at that level Compare it with the maximum sum found so far Track the level that gives the maximum sum If multiple levels have the same sum, return the smallest level ⏱️ Complexity Analysis Time Complexity: O(n) Space Complexity: O(n) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 71 of #100DaysOfCode Solved LeetCode Problem #2976 – Minimum Cost to Convert String I ✅ This problem revolved around graph algorithms and all-pairs shortest paths, where each character transformation had an associated cost. The key was efficiently finding the minimum cost to convert one string into another using allowed transformations. Key Learnings: -> Modeling character transformations as a weighted directed graph -> Applying Floyd–Warshall to precompute minimum conversion costs -> Handling unreachable transformations safely -> Aggregating per-character costs to compute the final answer Language Used: Java -> Runtime: 91 ms (Beats 13.62%) -> Memory: 48.16 MB (Beats 30.82%) Consistent progress, one problem at a time 🚀 On to the next challenge 💪 #LeetCode #Graphs #FloydWarshall #Java #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Implemented a Binary Search Tree (BST) from scratch in Java and stepped through the insertion logic using the debugger. Visualizing how nodes are placed (left < root < right) really reinforces core DSA fundamentals beyond just writing code. Inserted values: 7, 8, 1, 3, 2, 5, 10, 4 Focusing on strengthening my problem-solving skills one data structure at a time. #DataStructures #Java #DSA #ComputerScience #LearningByDoing #Debugging
To view or add a comment, sign in
-
-
LeetCode #961 – N Repeated Element in Size 2N Array Solved this problem using a HashMap-based frequency check in Java. Core Idea : In an array of size 2N, exactly one element appears N times, while all others appear once. So the moment any element’s frequency goes above 1, we’ve found the answer. 🔍 Approach : Traverse the array once Store frequencies using HashMap As soon as a number’s count becomes > 1, return it immediately This avoids unnecessary traversal and keeps the solution simple and readable. Complexity : Time: O(n) Space: O(n) ✔️ All test cases passed #LeetCode #LeetCode961 #DataStructures #HashMap #Java #ProblemSolving #DSA #CodingJourney #LearningByDoing
To view or add a comment, sign in
-
-
📅 Day 73 of #100DaysOfLeetCode 🧩 Problem: 3314. Construct the Minimum Bitwise Array I 📊 Difficulty: Easy 🧠 Key Insight For each prime number nums[i], we need to find the smallest non-negative integer x such that: x | (x + 1) == nums[i]. If no such value exists, the answer should be -1. ⚙️ Approach Initialize the answer array with -1 For each number nums[i]: Try all values of x from 0 to nums[i] - 1 Check if x | (x + 1) equals nums[i] As soon as a valid x is found, store it and stop searching If no valid value is found, keep -1 for that index ⏱ Complexity Time: O(n × max(nums[i])) Space: O(1) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 67 of #100DaysOfCode Solved LeetCode Problem #1984 – Minimum Difference Between Highest and Lowest of K Scores ✅ This problem focused on minimizing the score gap by smartly selecting k elements after sorting the array. A perfect example of how sorting + sliding window logic can turn a problem simple and efficient. Key Learnings: -> Sorting simplifies comparisons -> Sliding window to evaluate consecutive groups of size k -> Avoid brute force by leveraging order -> Small observations lead to clean solutions Language Used: Java -> Runtime: 8 ms (Beats 89.22%) -> Memory: 47.09 MB (Beats 25.34%) Consistency > Intensity 💪 On to the next challenge 🚀 #LeetCode #Java #ProblemSolving #Algorithms #Sorting #SlidingWindow #100DaysOfCode
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