🚀 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
LeetCode 3721: Longest Balanced Subarray II with Segment Tree
More Relevant Posts
-
Day 19 of Daily DSA 🚀 Solved LeetCode 2089: Find Target Indices After Sorting Array ✅ Approach: Instead of actually sorting the array, I counted: elements less than the target elements equal to the target The starting index is determined by how many elements are smaller than the target, and then indices are built for all equal elements. Simple counting → no extra sorting needed 💡 ⏱ Complexity: • Time: O(n) — single pass • Space: O(1) — excluding output list 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 44.83 MB (Beats 83.41%) A neat example of how thinking beyond “just sort it” can lead to cleaner and faster solutions. #DSA #LeetCode #Java #ProblemSolving #DailyCoding #Consistency #Arrays
To view or add a comment, sign in
-
-
🎯 Day 100 of #100DaysOfCode 🔥 What a way to wrap it up! Solved LeetCode #3666 – Minimum Operations to Equalize Binary String ✅ A problem that blends math, parity logic, and careful case analysis—not your usual binary flip question. Key takeaways: -> Count-based optimization over brute force -> Handling even/odd operation patterns smartly -> Early exits = cleaner & faster logic -> Thinking in terms of operations feasibility rather than simulation 🧠 Language: Java -> Runtime: 0 ms (Beats 83.87%) -> Memory: 47.90 MB 100 days. Countless problems. One habit built: consistency 💪 Onward to harder problems and deeper concepts 🚀 #LeetCode #Java #DSA #BinaryStrings #ProblemSolving #Consistency #100DaysChallenge
To view or add a comment, sign in
-
-
Day 11 of Daily DSA 🚀 Solved LeetCode 1394: Find Lucky Integer in an Array ✅ Approach: Iterated through the array and stored the frequency of each element using a HashMap. Then traversed the map to find integers whose value equals their frequency. Among all valid candidates, tracked and returned the maximum lucky integer. This approach ensures clarity and correctness with a straightforward counting strategy. ⏱ Complexity: • Time: O(n) — single pass to count + map traversal • Space: O(n) — extra space for frequency map 📊 LeetCode Stats: • Runtime: 5 ms (Beats 69.53%) ⚡ • Memory: 44.70 MB (Beats 99.01%) A good example of how HashMaps simplify frequency-based problems. #DSA #LeetCode #Java #HashMap #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Today I learned why converting large binary strings using Integer.parseInt() is a bad idea. Solved LeetCode 1404 – Number of Steps to Reduce a Number in Binary Representation to One. Initially, I tried converting the binary string into an integer. Got NumberFormatException. Reason? Binary length > 31 bits → overflow. So instead of converting, I: Processed the string from right to left Simulated carry manually Counted steps without using BigInteger Result: Runtime: 0 ms Beat: 100% Key takeaway: Sometimes the optimal solution is not about bigger data types — It’s about avoiding conversion entirely. #LeetCode #Java #ProblemSolving #DataStructures #Binar
To view or add a comment, sign in
-
-
Day 20 of Daily DSA 🚀 Solved LeetCode 179: Largest Number ✅ Approach: Converted all integers to strings and used a custom comparator while sorting. For two numbers a and b, we compare: a + b vs b + a This ensures the order that forms the largest possible number. Edge Case Handled 💡 If the highest element after sorting is "0", then the entire array contains zeros → return "0" instead of "000". ⏱ Complexity: • Time: O(n log n) — sorting with custom comparator • Space: O(n) — string array 📊 LeetCode Stats: • Runtime: 6 ms (Beats 96.21%) ⚡ • Memory: 44.96 MB (Beats 76.86%) Comparator-based problems really sharpen logical thinking 🔥 #DSA #LeetCode #Java #ProblemSolving #DailyCoding #Sorting #Consistency
To view or add a comment, sign in
-
-
🚀 Day 86 of #100DaysOfCode Solved LeetCode Problem #3714 – Longest Balanced Substring II ✅ This problem builds on Part I and demands a more optimized approach to track balance efficiently across the string. A great exercise in combining prefix-state tracking with hashing to avoid brute force. Key Takeaways: -> Using state compression to represent balance conditions -> Leveraging HashMap to store first occurrences for maximum length -> Thinking in terms of prefix differences rather than substrings -> Optimizing time complexity with smart observations Language: Java -> Runtime: 308 ms (Beats 77.17%) -> Memory: 156.78 MB Consistency compounds. One day, one problem. 💻🔥 #LeetCode #Java #DataStructures #Strings #HashMap #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 60: Work Smarter, Not Harder 🧠 Problem 1689: Partitioning Into Minimum Number Of Deci-Binary Numbers Today’s problem was a classic example of why you should analyze test cases before over-engineering a solution. The Strategy: • Initial Fail: Tried calculating the maximum deci-binary value before the target. Too complex, didn't work. 💀 • The "Aha" Moment: Realized that since deci-binary numbers only use 0s and 1s, the minimum number of partitions needed is simply determined by the largest digit in the string. • Logic: If you have a '9', you need at least nine deci-binary numbers to sum up to it. O(N) time, O(1) space, and zero stress. Sometimes the hardest part of a "Medium" problem is realizing how easy it actually is. 🚀 #LeetCode #Java #Algorithms #ProblemSolving #DailyCode #CleanCode
To view or add a comment, sign in
-
-
🚀 #100DaysOfCode | Day 36 📌 LeetCode – Path Sum Today I solved the Path Sum problem using a recursive Depth-First Search (DFS) approach. Given a binary tree and a target sum, determine whether there exists a root-to-leaf path such that the sum of all node values equals the target. 💡 Approach: ✔ If the node is null, return false. ✔ If it's a leaf node, check whether the remaining sum equals the node value. ✔ Recursively subtract the current node value from targetSum. ✔ Check both left and right subtrees. ✔ If either returns true → path exists. ⏱ Complexity: Time Complexity: O(n) Space Complexity: O(h) — height of the tree Binary tree problems are all about mastering recursion and understanding base cases clearly. #Java #LeetCode #DSA #BinaryTree #Recursion #ProblemSolving
To view or add a comment, sign in
-
-
Day 71/100 – LeetCode Challenge ✅ Problem: #1356 Sort Integers by The Number of 1 Bits Difficulty: Easy Language: Java Approach: Custom Comparator with Bit Counting Time Complexity: O(n log n) Space Complexity: O(n) Key Insight: Sort integers based on number of set bits (1s in binary representation). If bit counts are equal, sort by natural integer order. Use Integer.bitCount() for efficient population count. Solution Brief: Converted primitive array to Integer[] for custom sorting. Applied Arrays.sort() with comparator: Compare bitCount(a) vs bitCount(b) If equal, compare integers directly using a.compareTo(b) Converted back to primitive array. #LeetCode #Day71 #100DaysOfCode #Sorting #Java #Algorithm #CodingChallenge #ProblemSolving #SortByBits #EasyProblem #BitManipulation #Comparator #DSA
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
-
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