🚀 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
Maximizing Binary Tree Level Sums with BFS in Java
More Relevant Posts
-
🚀 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
To view or add a comment, sign in
-
-
Day 57/100 of #100DaysOfCode 🚀 “Count Good Nodes in a Binary Tree” problem on LeetCode.. A node is considered good if there is no node with a greater value on the path from the root to that node. Approach: ->Traversed the tree using recursion ->Passed the maximum value seen so far along the root-to-node path ->Compared the current node’s value with the max: ->If node.val >= max, it’s a good node ->Updated the max value before going deeper ->Recursively counted good nodes in left and right subtrees ->Summed up the counts to get the final result #Day57 #100DaysOfCode #LeetCode #BinaryTree #DFS #Recursion #Java #DSA #ProblemSolving #LearningEveryDay
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 66 of #100DaysOfCode | Top K Frequent Elements Solved Top K Frequent Elements using an efficient Bucket Sort–based approach in Java. Approach used: Count the frequency of each element using a HashMap Create a bucket array where the index represents frequency Traverse the buckets from highest to lowest frequency to collect the top k elements Why this approach is efficient: No need to sort the entire array Makes use of the frequency range (1 → n) Works well even for large inputs Time & Space Complexity: Time: O(n) Space: O(n) Key takeaways: Bucket Sort is extremely useful for frequency-based problems Understanding constraints leads to optimal solutions Clean logic beats overcomplicated code Consistency is the real win. On to Day 68 💪 #Day67 #DSA #Java #LeetCode #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day: 21/365 Problem: Minimum Cost Path with Edge Reversals Medium Key takeaways / learnings: 1. Graph problems can often be transformed by redefining edge weights to model constraints like reversals or penalties. 2. Dijkstra works even when the graph is transformed, as long as all edge weights are non-negative. 3. Thinking in terms of cost instead of steps helps solve non-standard shortest path problems. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #Consistency 🥷
To view or add a comment, sign in
-
-
Java records provide a modern, concise way to define classes that primarily serve as immutable data carriers. By replacing traditional classes, they eliminate extensive boilerplate code by automatically generating fields, constructors, equals, hashCode, and toString methods. If you want to learn more you can check this out : https://lnkd.in/gqm3DUkm #java17 #record #javalearning
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 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
-
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