🚀 Day 75 of #100DaysOfCode Solved LeetCode Problem #3013 – Divide an Array Into Subarrays With Minimum Cost II ✅ This one was a step up from Part I — combining sliding window logic with ordered data structures (TreeSet) to efficiently track minimum costs under constraints. Key Takeaways: -> Smart use of TreeSet for dynamic minimum tracking -> Handling window constraints (k, dist) cleanly -> Balancing correctness with performance in greedy-style problems -> Thinking beyond brute force for optimization Language: Java -> Runtime: 332 ms (Beats 47.83%) -> Memory: 105.54 MB Consistency > Perfection. One problem at a time. 💻🔥 #LeetCode #Java #DataStructures #Greedy #SlidingWindow #ProblemSolving #100DaysOfCode
Divide Array into Subarrays with Min Cost using TreeSet and Sliding Window
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
-
-
Started the matrix LeetCode practice today with 867. Transpose Matrix. This problem was straightforward in logic, but important for strengthening the row–column index relationship that keeps showing up in matrix questions. Approach used: - created a new matrix with swapped dimensions - mapped transpose[j][i] = matrix[i][j] using nested loops - focused on correctness and clarity rather than clever tricks Result : Accepted Runtime : 0 ms Beats: 100% (runtime) Main takeaway from this problem: - transpose is one of the most fundamental matrix transformations - many harder matrix problems secretly rely on this same idea - clean indexing matters more than complicated logic Good first step before moving to rotation and spiral traversal problems. #LeetCode #DSA #Matrices #Java #ProblemSolving #CodingJourney #LearningInPublic #JavaDeveloper
To view or add a comment, sign in
-
-
🚀 Day 84 of #100DaysOfCode Solved LeetCode Problem #3721 – Longest Balanced Subarray II ✅ This one was a solid jump in complexity from Part I. It required a more advanced approach using segment trees with lazy propagation to efficiently handle range updates and queries while tracking balance conditions. Key Takeaways: -> Segment Tree + Lazy Propagation is powerful for range-based balance problems -> Encoding states smartly simplifies transitions -> Performance optimization matters when brute force isn’t an option -> Advanced data structures unlock solutions to “Part II” style problems Language: Java -> Runtime: 349 ms (Beats 73.53%) ⚡ -> Memory: 72.05 MB (Beats 98.53%) One day, one hard problem, steady progress. 💻🔥 #LeetCode #Java #SegmentTree #LazyPropagation #DataStructures #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
-
-
Continued the matrix LeetCode practice with 48. Rotate Image. Unlike transpose, this problem required rotating the matrix in-place, which means no extra matrix could be used. That constraint made the logic more interesting. Approach used: - first performed a transpose across the main diagonal - then reversed each row to complete the 90° clockwise rotation - kept the focus on clear index manipulation instead of complex tricks Result : Accepted Runtime : 0 ms Clean in-place transformation without extra space Key learning from this problem: - many matrix rotations are just transpose + reverse in disguise - in-place operations demand careful index handling - understanding the pattern is more valuable than memorizing code This felt like a natural step forward from transpose toward more complex traversal and matrix logic. #LeetCode #DSA #Matrices #Java #ProblemSolving #CodingJourney #LearningInPublic #JavaDeveloper
To view or add a comment, sign in
-
-
Day 44: Avoiding the O(n²) Trap 🔍 Problem 3714: Longest Balanced Substring II Today’s goal: find the longest substring where all present characters appear equally. Since we only had 'a', 'b', and 'c' to deal with, I split the logic into three cases (1, 2, or 3 unique characters). Pro tip: I almost nuked my runtime by using map.clear() inside a loop. Since clear() iterates over the map to nullify entries, it’s O(n). Switching to new HashMap<>() kept the complexity at a clean O(1) reset and a total O(n) pass. Don't let built-in methods turn your linear solution into a nested nightmare. Complexity matters. 🧗♂️ #LeetCode #Java #CodingChallenge #ProblemSolving
To view or add a comment, sign in
-
-
LeetCode 1752 — Check if Array Is Sorted and Rotated Solved another array logic problem today. At first it looked simple, but the real task was to observe the pattern in order changes, not just compare numbers blindly. Approach I used: - counted how many times the order breaks (nums[i] > nums[i+1]) - if it breaks more than once → not sorted & rotated - if it breaks once → last element must still fit before the first - otherwise → already sorted Result : Accepted Runtime : 0 ms What this problem made clear: - many array problems are really about pattern detection - a small logical observation can replace complex code - edge cases decide whether the solution is correct or not Small step, but clear learning. Continuing the grind. #LeetCode #DSA #Arrays #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 85 of #100DaysOfCode Solved LeetCode Problem #3713 – Longest Balanced Substring I ✅ A classic string + frequency-based problem that rewards careful iteration and validation. The goal was to find the longest substring where all present characters appear the same number of times—simple idea, but requires disciplined checking. Key Takeaways: -> Brute-force with pruning can still pass when constraints allow -> Frequency arrays are powerful for substring analysis -> Early balance checks save unnecessary computation -> Always align solution strategy with input limits Language: Java -> Runtime: 83 ms (Beats 88.95%) ⚡ -> Memory: 47.29 MB Small wins matter. Staying consistent, one problem at a time. 💻🔥 #LeetCode #Java #Strings #ProblemSolving #Algorithms #100DaysOfCode
To view or add a comment, sign in
-
-
#Day32 of #365DaysOfCode Today’s LeetCode Practice: 🔹 Container With Most Water (LeetCode 11) Solved a classic two-pointer optimization problem where the goal is to find two lines that together form a container holding the maximum water. 💡 Key Insight: Start with two pointers at both ends. Calculate area using: width × min(height[left], height[right]) Move the pointer with the smaller height inward, because the smaller height limits the water capacity. This guarantees exploring better possibilities efficiently. ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) Consistency > Motivation. Day by day, improving problem-solving and logical thinking skills #LeetCode #ProblemSolving #Java #CodingJourney #FutureEngineer #Consistency #LearningEveryday
To view or add a comment, sign in
-
-
Day 22 of Daily DSA 🚀 Solved LeetCode 66: Plus One ✅ Approach: Treat the array as a number and simulate addition from the last digit: • If the last digit is not 9, increment and return • Handle carry by setting 9 → 0 and moving left • If all digits are 9, create a new array with leading 1 This avoids converting the array into an integer and handles large numbers safely. ⏱ Complexity: • Time: O(n) • Space: O(1) (extra array only when overflow happens) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.58 MB (Beats 38.49%) A simple problem that tests edge-case thinking 💡 #DSA #LeetCode #Java #ProblemSolving #DailyCoding #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