Logic: 100%. Syntax: ...Loading? 😅 Today’s LeetCode Daily (Maximum Level Sum of a Binary Tree) was a rollercoaster. I looked at the problem and immediately clicked: "This is a Breadth-First Search (BFS) problem, easy!" 🧠💡 But then came the implementation... I confess, I had to take a quick peek at the docs to remember how to properly set up a Queue in Java for the traversal. It’s funny how you can have the algorithmic logic perfectly mapped out in your head, but the specific syntax decides to take a coffee break. ☕ Got the green checkmark in the end! ✅ Current Status: 🚀 Runtime: Beats 64% 📉 Memory: Beats 56% The logic works, but looking at those charts, I know there's room for improvement. Next goal: diving deeper into optimizing the time complexity and cleaning up the memory usage. Progress > Perfection! #LeetCode #Java #CodingJourney #BFS #SoftwareEngineering #AlwaysLearning
Maximizing Binary Tree Sum with BFS in Java
More Relevant Posts
-
Day 47/100 – LeetCode Challenge ✅ Problem: #3013 Divide an Array Into Subarrays With Minimum Cost II Difficulty: Hard Language: Java Approach: Order Statistics with Balanced Trees Time Complexity: O(n log n) Space Complexity: O(n) Key Insight: Track greater count efficiently for two arrays during distribution. Need to compare current element with elements in both arrays - count how many are strictly greater. Used two TreeMaps to maintain sorted frequency counts with lazy rebalancing. Solution Brief: Maintained two balanced multisets (TreeMaps) for both arrays with size management. For each element, computed greater counts using total sizes and tail map views. Rebalanced collections when size constraints were violated to maintain optimal query performance. Advanced data structures for dynamic order statistics #LeetCode #Day47 #100DaysOfCode #HardProblem #DataStructures #TreeMap #Java #Algorithm #CodingChallenge #OrderStatistics #BalancedTrees
To view or add a comment, sign in
-
-
🔍 Method Overloading - Simple in Syntax, Subtle in Practice Method overloading looks straightforward on the surface, but in real systems, it can introduce subtle behavior if we’re not careful. At a high level, method overloading allows multiple methods with the same name but different parameter lists. The compiler decides which method to call at compile time based on the method signature. Example: calculate(int a, int b) calculate(double a, double b) calculate(int a, int b, int c) Sounds simple, but here’s where experience kicks in 👇 What I’ve learned using overloading in real projects: • Overloading improves readability when methods represent the same logical action with different inputs • Ambiguous overloads (especially with null, autoboxing, or varargs) can lead to unexpected method resolution • Overusing overloads can reduce clarity, especially in large APIs • In public APIs, fewer well-named methods often age better than many overloaded ones One key thing to remember: Overloading is resolved at compile time, not runtime; unlike overriding, which depends on polymorphism. In enterprise codebases, I’ve found overloading most effective when: • The behavior is conceptually identical • Parameter differences are obvious and intentional • Method names remain expressive, not overloaded for convenience Like many Java features, overloading is powerful, but only when used with restraint and clarity. Curious to hear how others decide when to overload vs when to create separate methods 👇 #Java #SoftwareEngineering #CleanCode #BackendDevelopment #ProgrammingPrinciples
To view or add a comment, sign in
-
-
🚀 Day 68 of #100DaysOfCode Solved LeetCode Problem #1200 – Minimum Absolute Difference ✅ A clean and elegant problem where sorting does most of the heavy lifting. By comparing adjacent elements after sorting, we can efficiently find all pairs with the minimum absolute difference. Key Learnings: -> Sorting simplifies difference-based problems -> Adjacent comparison is enough after sorting -> Clear logic beats complex data structures -> Collecting results while tracking the minimum difference Language Used: Java -> Runtime: 20 ms (Beats 97.70%) -> Memory: 64.05 MB (Beats 32.62%) Step by step, day by day 🚀 On to the next problem 💪 #LeetCode #Java #ProblemSolving #Algorithms #Sorting #Arrays #100DaysOfCode
To view or add a comment, sign in
-
-
🔥 Day 95/100 of Code – Combination Sum: Backtracking with Unlimited Reuse! Today returned to a classic backtracking problem — foundational for combinatorial search: ✅ Problem 39: Combination Sum Task: Find all unique combinations (with repetition allowed) that sum to target. Approach: Recursive backtracking with index control: At each step, decide to include current candidate (if ≤ remaining target) or skip it If included, stay at same index (allow reuse) If target reaches 0, add current combination to result Use pruning to avoid unnecessary recursion Key Insight: By staying at same index when including, we allow unlimited reuse. By moving to next index when skipping, we ensure all combinations are explored without duplicates. Complexity: O(2^target) worst-case time, O(target) recursion depth. A perfect example of how backtracking elegantly handles "choose with repetition" problems — building solutions incrementally! 🧩🔢 #100DaysOfCode #LeetCode #Java #Backtracking #DFS #Combinations #Algorithm
To view or add a comment, sign in
-
-
LeetCode Practice - 944. Delete Columns to Make Sorted 🧠 Problem Idea ✅ You are given n strings, all of the same length. ✅ Imagine them written one below another like a grid. Example: cba daf ghi We check column by column. Column 0 → c d g → sorted ✅ Column 1 → b a h → NOT sorted ❌ Column 2 → a f i → sorted ✅ So we delete column 1 → answer = 1 🛠️ Key Observation ✅ A column is sorted if characters do not decrease from top to bottom. That means: 📌 strs[0][col] <= strs[1][col] <= strs[2][col] <= ... ✅ If any pair breaks this rule, that column must be deleted. 🚀 Algorithm 🔷 Take number of rows n 🔷 Take the n strings 🔷 For each column 🔷 Compare every row with the next row 🔷 If upperRowChar > lowerRowChar, mark it as invalid 🔷 Count how many columns are invalid #LeetCode #Java #StringHandling #CodingPractice #ProblemSolving #DSA #DeveloperJourney #TechLearning
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
-
-
🚀 Day 56 of #100DaysOfCode Solved LeetCode Problem #3454 – Separate Squares II. This was a more advanced extension of Separate Squares I, requiring a deeper geometric insight. The problem focused on finding a horizontal line that splits the total area of multiple squares equally, but this time with overlapping projections, making it significantly more challenging. Key Learnings: -> Applied sweep line technique with event-based processing -> Managed overlapping x-intervals efficiently -> Calculated area contributions dynamically while sweeping along the y-axis -> Strengthened understanding of computational geometry + precision handling Language Used: Java -> Runtime: 191 ms (Beats 81.13%) -> Memory: 115.22 MB (Beats 76.42%) From binary search to sweep line — evolving step by step 🚀 #LeetCode #ComputationalGeometry #SweepLine #Java #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Problem Number : 1475 LeetCode Solution | Monotonic Stack in Java I recently solved the problem “Final Prices With a Special Discount in a Shop” using an optimized Monotonic Stack approach in Java. 🔍 Approach Overview Used a stack to store indices instead of values Maintained a monotonically increasing stack Applied the discount as soon as a smaller or equal price was found Achieved an optimal O(n) time complexity 🧠 Key Takeaways ✔ Clear understanding of why prices[stack.peek()] >= prices[i] works ✔ Practical use of stack for real-world pricing logic ✔ Improved problem-solving using pattern-based DSA (Monotonic Stack) 📌 Problem Link: 👉 https://lnkd.in/gNz36t-f I’m actively strengthening my Data Structures & Algorithms foundation through consistent practice and real problem solving. Always open to feedback, discussions, and learning from the community. #LeetCode#Java#DataStructuresAndAlgorithms#MonotonicStack#ProblemSolving#SoftwareDevelopment#CodingPractice#LearningJourney#TechCommunity
To view or add a comment, sign in
-
-
Today I solved LeetCode 77 – Combinations using a backtracking approach. The problem asks us to generate all possible combinations of k numbers chosen from 1 to n. Instead of brute force, I used recursion with pruning to reduce unnecessary calls and improve efficiency. Key idea: Build combinations step by step Backtrack when the size reaches k Prune branches where remaining elements are insufficient Here is my Java solution: class Solution { List<List<Integer>> sol = new ArrayList<>(); public List<List<Integer>> combine(int n, int k) { generate(1, n, k, new ArrayList<>()); return sol; } public void generate(int i, int n, int k, List<Integer> sub) { if (k == 0) { sol.add(new ArrayList<>(sub)); return; } for (int j = i; j <= n - k + 1; j++) { sub.add(j); generate(j + 1, n, k - 1, sub); sub.remove(sub.size() - 1); } } } Time Complexity: O(C(n, k)) Space Complexity: O(k) This problem strengthened my understanding of recursion, pruning, and combinatorial generation. Always open to feedback and discussions. #LeetCode #Java #Backtracking #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
Day 20/60: Binary Search Trees — The Reality Check 🔍 Today was about implementing Binary Search Trees (BST) in Java. While the concept is simple, the implementation exposed some critical gaps in my recursive logic. The Hurdles & Mistakes: The Return Value Trap: I struggled with returning the correct node during recursion. In Java, if you don't link the returned node back to the parent (root.left = insert(...)), the new node is lost and the tree never grows. Missing Base Cases: I missed a null check on an empty tree, leading to an immediate NullPointerException. In backend development, unhandled nulls are production killers. Duplicate Handling: I didn't initially plan for existing values. Deciding how to handle duplicates is crucial for defining consistent system behavior. The Lessons: Visualize First: I stopped coding and started drawing. If you can’t trace the recursion on paper, you can’t debug it in the IDE. Defensive Coding: I’m learning to write the "Exit Condition" first. Knowing when to stop is more important than knowing how to proceed. State Management: BSTs taught me that how we structure data at the point of entry determines the speed of every future query. Status: ✅ Fixed: Recursive Insertion and Search logic. 🛠️ Working on: Visualizing the call stack deeper. 🎯 Goal: Day 21 – Mastering the three cases of Node Deletion. Refining the logic, one error at a time. 🚀 #JavaDeveloper #Backend #60DaysOfDSA #BinarySearchTree #CodingHurdles #SoftwareEngineering #LearningInPublic
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