🚀 Day 89 of #100DaysofLeetCode Problem: Minimum Size Subarray Sum Difficulty: Medium Today’s challenge was about finding the smallest length subarray whose sum is greater than or equal to a given target. Since all elements are positive, this problem is a perfect fit for the Sliding Window technique. Instead of checking all possible subarrays (which would be inefficient), I used two pointers: Expand the window by moving the right pointer and adding to the current sum. Once the sum becomes ≥ target, shrink the window from the left to find the minimum possible length. Keep updating the minimum length during this process. Key takeaways: Positive integers allow efficient window shrinking. Two pointers help reduce time complexity from O(n²) to O(n). Maintain a running sum and dynamically adjust window size. Return 0 if no valid subarray exists. Time Complexity: O(n) Space Complexity: O(1) Another solid sliding window problem completed 💪 #100DaysOfCode #100DaysOfLeetCode #LeetCode #DSA #SlidingWindow #TwoPointers #Java #ProblemSolving #CodingJourney #Algorithms
Minimum Size Subarray Sum with Sliding Window Technique
More Relevant Posts
-
Day 45 on LeetCode Largest Submatrix With Rearrangements :- This problem clicked once I stopped treating columns as fixed. Rearranging them turns each row into a controllable histogram. Approach: ->Build vertical heights of consecutive 1s ->Sort each row to simulate optimal column order ->Evaluate max area using height × width Time Complexity: O(m × n log n) The editorial on LeetCode made the difference here. It didn’t just give the solution, it clarified the intuition behind sorting heights, which is easy to miss on your own. #DSA #LeetCode #Java
To view or add a comment, sign in
-
-
🚀 Day 45 / 100 | Longest Substring Without Repeating Characters Intuition: The problem is to find the length of the longest substring without repeating characters. If a repeated character appears, the substring must be adjusted to remove duplicates. Using a sliding window approach, it maintain a window of unique characters while scanning the string. Approach: O(n) -Use a HashSet to store characters currently in the substring window. -Maintain two pointers: left and right . -Iterate through the string using the right pointer. -If the character already exists in the set, remove characters from the left until the duplicate is removed. -Add the current character to the set. -Update the maximum length of the substring using the window size. -Repeat this process until the end of the string. Complexity: Time Complexity: O(n) Space Complexity: O(n) #100DaysOfCode #Java #DSA #LeetCode #SlidingWindow
To view or add a comment, sign in
-
-
100 Days of Code Day-14 Solved a classic problem: Longest Common Prefix Given an array of strings, the task is to find the longest common prefix shared among them. If no common prefix exists, return an empty string. Approach: Used a simple horizontal scanning method: Start with the first string as the prefix Compare it with each string Gradually reduce the prefix until it matches all strings Example: "flower", "flow", "flight" → "fl" "dog", "racecar", "car" → "" A good exercise to strengthen string handling and logical thinking. #Java #DSA #ProblemSolving
To view or add a comment, sign in
-
-
Day 56 of 365 🚀 Maximum Product of Two Elements in an Array 🧠 Simple problem. Clean logic. Zero extra space. The task: find two largest numbers in an array, subtract 1 from each, multiply that's your answer. The approach? Track the top 2 values in a single pass. No sorting. No extra array. Just two variables doing all the work. Time: O(n) | Space: O(1) The real lesson here isn't the problem itself it's the habit of asking "do I really need to sort this?" before reaching for Arrays.sort(). Most of the time, a linear scan is enough. 🎯 Day 56. Showing up. ✅ #365DaysDSAChallenge #DSA #LeetCode #Java #CodingChallenge #BackendDeveloper #LinkedInLearning
To view or add a comment, sign in
-
-
Day 37/100 🚀 | #100DaysOfDSA Solved Reverse String by Character Type – LC 3823 This problem required reversing characters in a string — but with a twist. Letters and special characters had to be reversed within their own groups while keeping their original positions relative to each other. Example idea: Letters reverse among letters, special characters reverse among specials. My Approach: • Converted the string to a character array for easier traversal. • Used two stacks — one for letters and one for special characters. • First pass: pushed characters into their respective stacks. • Second pass: rebuilt the string by popping from the correct stack depending on the character type. Time Complexity: O(n) Space Complexity: O(n) Key Learning: Breaking a problem into categories can simplify the logic significantly. Once characters were separated by type, reconstructing the result became straightforward. Small problems. Clear thinking. Consistent progress. 💪 #100DaysOfCode #LeetCode #DSA #Java #Strings #Stacks #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 531 of #750DaysOfCode 🚀 💻 LeetCode 1415 — The K-th Lexicographical Happy String of Length n Today’s problem was a great practice of Backtracking + Recursion + Lexicographical order generation. We are given a length n and a number k, and we need to find the k-th happy string in sorted order. 🔹 A happy string means: Only contains characters → a, b, c No two adjacent characters are same Example: Valid → "abc", "acb", "bab" Invalid → "aa", "abb", "bcc" The challenge was to generate all valid strings in lexicographical order and return the k-th one. 💡 Approach Used: Backtracking (DFS) Try characters in order → a, b, c Skip same adjacent character Stop early when k-th string found This problem improved my understanding of: ✔ Recursion ✔ Backtracking ✔ String generation ✔ Lexicographical traversal ✔ Early stopping optimization Consistency is the key — one problem every day, no excuses. 🔥 #750DaysOfCode #Day531 #LeetCode #Java #Backtracking #Recursion #DSA #CodingJourney #SoftwareEngineer #PlacementPreparation
To view or add a comment, sign in
-
-
🚀 Day 30 / 100 | First Missing Positive -Intuition: The smallest missing positive will always be in range 1 to n+1. Place each number at its correct index (1 at index 0, 2 at index 1 so on). First index where value ≠ index+1 gives the missing number. -Approach : O(n) Find length of array n Traverse array and place each element at correct position -> index = value − 1 Ignore negative numbers, zero, and numbers > n After placement, traverse array again If arr[i] ≠ i+1 -> return i+1 If all elements are correct -> return n+1 -Complexity: Time Complexity : O(n) Space Complexity : O(1) #100DaysOfCode #Java #DSA #Array #LeetCode
To view or add a comment, sign in
-
-
Day 44 of DSA 🚀 Solved Minimum Number of Flips to Make the Binary String Alternating. 💡 Key Insight: An alternating binary string can only follow two patterns: 010101... 101010... To handle rotations efficiently: Double the string (s + s) Use a sliding window of size n Count mismatches with both patterns Track the minimum flips required. ⏱ Time: O(n) 💾 Space: O(n) Good practice for sliding window + pattern matching. #DSA #Java #LeetCode #100DaysOfCode
To view or add a comment, sign in
-
-
#100DaysOfCode 🚀 👉Solved: LeetCode #16 – 3Sum Closest After solving the classic 3Sum problem earlier, this variation pushed me to think slightly differently. Instead of finding an exact triplet sum equal to 0, this time the goal was to find the sum *closest* to a given target. 🔹 Approach: • Sorted the array • Fixed one element at a time • Applied the Two Pointer technique • Continuously tracked the minimum absolute difference Key Insight: Sometimes optimization problems are not about exact matches, but about minimizing deviation. Time Complexity: O(n²) Space Complexity: O(1) This problem strengthened my understanding of: ✔ Two Pointers ✔ Greedy comparison logic ✔ Edge case handling What I learned: Small variations in problem statements can completely change the thinking approach. Classic 3Sum focuses on exact zero. 3Sum Closest focuses on minimizing |sum - target|. #LearnInPublic #DSA #Java #LeetCode #TwoPointers #ProblemSolving #CodingJourney #SoftwareEngineering
To view or add a comment, sign in
-
-
🎯 Day 67 of #100DaysOfCode 📌 Problem: Combination Sum Today's challenge was all about finding all unique combinations of candidates where the chosen numbers sum to a given target. The same number can be used unlimited times, and combinations must be unique. 🧠 Approach: Used dynamic programming with a 3D list structure dp[t] stores all combinations that sum to target t Iterated through candidates and built combinations from smaller sums Extended each valid combination by adding current candidate 📊 Stats: ✅ 160/160 test cases passed ⚡ Runtime: 5 ms | Beats 10.10% 💾 Memory: 46.71 MB | Beats 5.88% 📝 Takeaway: This problem highlighted the trade-off between intuitive DP solutions and optimization. While the approach works, there's room for improvement in both runtime and memory efficiency. Backtracking might be a more elegant solution here! 🔗 Problem: Combination Sum 🏷️ #LeetCode #CodingChallenge #Java #DynamicProgramming #Backtracking #Algorithms #TechJourney #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