🚀 Day 61 of #100DaysOfCode Solved LeetCode Problem #1292 – Maximum Side Length of a Square with Sum ≤ Threshold 🟦 This problem revolved around efficiently finding the largest possible square submatrix whose total sum does not exceed a given threshold. A great mix of 2D prefix sums and greedy expansion. Key Learnings: -> Built a 2D prefix sum matrix to compute submatrix sums in O(1) -> Used incremental square expansion to avoid unnecessary recomputation -> Learned how prefix sums simplify range-sum constraints in grids -> Balanced correctness with performance for tight constraints Language Used: Java -> Runtime: 5 ms (Beats 99.49%) -> Memory: 57.82 MB (Beats 27.92%) Another day, another step forward in mastering matrix-based DP and prefix sum techniques 🚀 #LeetCode #Java #PrefixSum #DynamicProgramming #Matrix #ProblemSolving #100DaysOfCode
Maximizing Square Size with Prefix Sums in Java
More Relevant Posts
-
🚀 Day 80 of #100DaysOfCode Solved LeetCode Problem #1653 – Minimum Deletions to Make String Balanced ✅ A clean greedy + DP-style problem that looks simple but really tests decision-making at each step. The trick is choosing whether to delete a character now or rely on previous counts to minimize total deletions. Key Takeaways: -> Greedy decisions can be optimized with running state -> Tracking counts (bCount) simplifies future choices -> Sometimes the best DP is just two variables -> Elegant logic beats complex data structures Language: Java -> Runtime: 19 ms (Beats 93.09%) ⚡ -> Memory: 47.80 MB Showing up daily, sharpening logic, and trusting the process. 💻🔥 #LeetCode #Java #Greedy #DynamicProgramming #Strings #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 81 of #100DaysOfCode Solved LeetCode Problem #110 – Balanced Binary Tree ✅ A classic tree problem that rewards thinking bottom-up. Instead of recalculating heights repeatedly, combining height computation with balance checking makes the solution both clean and efficient. Key Takeaways: -> Bottom-up recursion simplifies tree problems -> Early termination saves unnecessary computation -> Returning sentinel values (-1) is a powerful pattern -> One DFS can solve both height & balance checks Language: Java -> Runtime: 0 ms (Beats 100%) ⚡ -> Memory: 45.76 MB Staying consistent, one tree at a time. 🌳💻🔥 #LeetCode #Java #BinaryTree #Recursion #DFS #ProblemSolving #100DaysOfCode
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
-
-
Day 52/100 – LeetCode Challenge ✅ Problem: #1653 Minimum Deletions to Make String Balanced Difficulty: Medium Language: Java Approach: Greedy with Counter Time Complexity: O(n) Space Complexity: O(1) Key Insight: String must be of form aa...abb...b (all 'a's before 'b's). For each 'a' encountered after a 'b', we must delete either this 'a' or a previous 'b'. Greedily delete 'a' when it appears out of order. Solution Brief: Tracked count of 'b's seen so far. When encountering 'a': If no preceding 'b's, it's in correct position If there are preceding 'b's, delete this 'a' (increment result) and reduce 'b' counter Final result = minimum deletions needed. #LeetCode #Day52 #100DaysOfCode #Greedy #Java #Algorithm #CodingChallenge #ProblemSolving #StringBalance #MediumProblem #Counter #Optimization #DSA
To view or add a comment, sign in
-
-
🚀 #100DaysOfCode – Day 12 Solved Search in Rotated Sorted Array II on LeetCode 🔄🔍 🧠 Key insight: When duplicates are present, it’s not always possible to directly identify the sorted half. If nums[left] == nums[mid], we can safely move left++ to reduce the search space and continue. ⚙️ Approach: 🔹Use modified binary search 🔹Handle duplicates by skipping equal boundary elements 🔹Identify the sorted half 🔹Check if the target lies in that range and adjust pointers accordingly ⏱️ Time Complexity: Average: O(log n) Worst case (many duplicates): O(n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #BinarySearch #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
Headline: Day 10/100: The Multiplier Effect 🍫✂️ Double digits! Today I tackled the "Minimum Cost to Cut a Board" problem—a classic Greedy challenge that taught me a valuable lesson about timing. The Problem: You have a board and a set of costs for horizontal and vertical cuts. How do you cut it into 1x1 squares for the lowest price? The Logic: It’s all about the "multiplier." Every cut you make increases the number of pieces for the opposite direction. The Greedy choice? Always make the most expensive cuts first. By doing the big-budget cuts while the board is still in fewer pieces, you prevent those costs from being multiplied later on. Key Technical Takeaways: ✅ Sorting primitive arrays in descending order in Java. ✅ Managing "piece counters" for horizontal and vertical segments. ✅ Understanding why the order of operations changes the total cost from $O(1)$ to $O(N)$. 10 days down, 90 to go. The logic is getting sharper every day! 🚀 #100DaysOfCode #GreedyAlgorithms #Java #CodingChallenge #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 72 of #100DaysOfCode Solved LeetCode Problem #2977 – Minimum Cost to Convert String II ✅ This was a more advanced follow-up that required handling string-level transformations efficiently. The challenge was to minimize the total cost by choosing optimal substring conversions rather than single-character changes. Key Learnings: -> Using a Trie to store and index valid string transformations -> Modeling transformation costs with dynamic programming -> Combining Trie traversal + DP for efficient substring matching -> Carefully managing state transitions to avoid unnecessary recomputation Language Used: Java -> Runtime: 209 ms (Beats 34.88%) -> Memory: 48.68 MB (Beats 18.60%) Step by step, leveling up problem-solving depth and string algorithm intuition 🚀 #LeetCode #DynamicProgramming #Trie #Java #ProblemSolving #100DaysOfCode
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
-
-
Solved two important Matrix problems in Java today 1. Set Matrix Zeroes Implemented a better approach using extra row and column arrays Then explored the optimal approach using the first row and column as markers Helped me understand space optimization concepts more clearly 2. Rotate Image (Matrix Rotation) First transposed the matrix (diagonal swapping logic) Then reversed each row to achieve 90° rotation Strengthened my understanding of in-place matrix manipulation Gradually becoming more comfortable with matrix problems in DSA. Trying to stay consistent and improve step by step 🙂 Code is available on my GitHub 👇 https://lnkd.in/g-Km2-kt If anyone has suggestions or knows a better approach, please feel free to share 🙌 #DSA #Java #MatrixProblems #ProblemSolving #CodingJourney #LearningInPublic #Consistency
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