📌 Day 4/100 - Minimum Size Subarray Sum (LeetCode 209) 🔹 Problem: Given an array of positive integers and a target value, find the minimal length of a contiguous subarray whose sum is greater than or equal to the target. If there’s no such subarray, return 0. 🔹 Approach: Used the Sliding Window technique for an optimized solution: Initialize two pointers (low, high) and a running sum. Expand the window by moving high until the sum ≥ target. Once valid, shrink the window from the left to find the smallest subarray. Keep updating the minimum length throughout. This reduced the time complexity from O(n²) (brute force) to O(n). 🔹 Key Learning: Sliding Window is ideal for problems with contiguous subarrays. Optimization often comes from adjusting the window efficiently. Each problem strengthens logical flow and pattern recognition. Another step forward in mastering DSA and problem-solving consistency! ⚡ #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingChallenge #SlidingWindow
How to solve LeetCode 209 with Sliding Window technique
More Relevant Posts
-
🔹 Day 40 – LeetCode Practice Problem: Find Greatest Common Divisor of Array (LeetCode #1979) 📌 Problem Statement: Given an integer array nums, find the greatest common divisor (GCD) of the smallest and largest numbers in the array. ✅ My Approach (Java): 1. Find the minimum and maximum elements in the array. 2. Starting from the smaller number and going downwards, check for the highest integer that divides both min and max. 3. Return that integer as the GCD. 📊 Complexity: Time Complexity: O(n + min(a, b)) Space Complexity: O(1) ⚡ Submission Results: Accepted ✅ Runtime: 0 ms (Beats 100%) 🚀 Memory: 43.41 MB (Beats 41.55%) 💡 Reflection: This problem shows how basic math logic and loop optimization can lead to extremely efficient solutions. A simple and powerful way to practice number theory in coding! #LeetCode #ProblemSolving #Java #DSA #CodingPractice #Learning
To view or add a comment, sign in
-
-
📌 Day 159 of Coding - Make Array Elements Equal to Zero (LeetCode - Easy) 🎯 Goal: Given an integer array nums, find the number of valid starting positions and directions such that by repeatedly decrementing and reversing direction (based on the rules), all elements eventually become 0. 💡Approach & Debugging: First computed total sum using Arrays.stream(nums).sum(). Maintained two prefix sums : left and right. For each index i where nums[i] == 0: Incremented left and decremented right progressively. Checked whether the left and right sums balance according to the movement rules. Counted valid selections when the balance was perfect or off by just one. ✔️ Time Complexity: O(N) - single pass through the array. ✔️ Space Complexity: O(1) - constant extra space. #Day159 #LeetCode #Simulation #Arrays #PrefixSum #Java #ProblemSolving #DSA #CodingChallenge #100DaysOfCode #Algorithms #InterviewPrep #SoftwareEngineering #DataStructures #CodeNewbie #ProgrammersLife
To view or add a comment, sign in
-
-
💻 Day 11 of #100DaysOfLeetCode – Rotate Image Today’s challenge was “Rotate Image”, a classic matrix manipulation problem that tests both logic and spatial reasoning. 🔹 Problem Statement: Given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise) — all in place, without using extra memory for another matrix. 🔹 My Approach (in Java): I used a two-step in-place transformation technique: 1️⃣ Transpose the matrix — swap elements across the diagonal (matrix[i][j] ↔ matrix[j][i]). 2️⃣ Reverse each row — to achieve the 90° clockwise rotation. This approach ensures O(1) extra space and O(n²) time complexity, which is optimal for this problem. 🔹 Key Takeaways: ✅ Learned how matrix transformations can be broken down into simpler operations. ✅ Improved understanding of in-place algorithms and memory efficiency. ✅ Reinforced clean coding habits and edge case handling. Every rotation brings me one step closer to mastering problem-solving patterns! 💪 #100DaysOfLeetCode #CodingJourney #RotateImage #Java #DSA #ProblemSolving #LeetCode #CodingChallenge #LearningEveryday
To view or add a comment, sign in
-
-
📌 Day 154 of Coding - Check If Digits Are Equal in String After Operations I (LeetCode - Medium) 🎯 Goal: Given a numeric string s, repeatedly replace it with a new string formed by taking the sum (mod 10) of every pair of adjacent digits, until only two characters remain. Return whether the final two digits are equal. 💡Approach & Debugging: Used a simple iterative simulation approach. For each iteration, formed a new string res by summing adjacent digits modulo 10. Replaced s with res and continued until the string length dropped to 2. Finally, compared both digits for equality. ✔️ Time Complexity: O(N*N) - since the string shrinks gradually each iteration. ✔️ Space Complexity: O(N) - temporary strings. 🧠 Key Takeaways: Some problems test simulation and string manipulation more than algorithms. Always track how input size evolves after each iteration. #Day154 #LeetCode #StringManipulation #Java #ProblemSolving #DSA #CodingChallenge #Algorithms #100DaysOfCode #InterviewPrep #SoftwareEngineering #DataStructures #CodeNewbie #ProgrammersLife
To view or add a comment, sign in
-
-
📌 Day 18/100 - Valid Palindrome (LeetCode 125) 🔹 Problem: Determine whether a string reads the same forward and backward, ignoring case and non-alphanumeric characters. 🔹 Approach: Implemented a two-pointer technique. Skipped all non-alphanumeric characters. Compared characters from both ends in lowercase. Returned true if all matched, otherwise false. 🔹 Key Learning: Two-pointer method keeps logic clean and efficient. Character handling is key when data isn’t uniform. Time complexity: O(n), Space complexity: O(1). Sometimes, solving elegantly is better than solving fast. ✨ #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney
To view or add a comment, sign in
-
-
Day 87/100 of DSA & LeetCode grind 🔥 Today's problem: 3318. Find X-Sum of All K-Long Subarrays I What I learned: • It's not always about prefix sums or classic sliding window. • Sometimes the real game is frequency + ordering logic. • For every window of size k, we: Count freq of each number Keep only the top x most frequent values (tie-break by bigger value 😮) Sum value * freq for those Key skills practiced: ✅ HashMap for freq tracking ✅ Sliding window add/remove in O(1) ✅ Custom sorting rule (by freq desc, value desc) ✅ Turning the problem statement into steps that code can actually do Why I liked this problem: This is the type of question that looks like brute force, but teaches you how to maintain state while the window moves. That's super important for real interviews. Mindset: DSA is not just solving one question. It's building patterns you can reuse. Still going. Still consistent. 🚀 #Day87 #LeetCode #DSA #100DaysOfCode #Java #SlidingWindow #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
📌 Day 32/100 – Count and Say (LeetCode 38) 🔹 Problem: Given an integer n, return the nth term of the Count and Say sequence, where each term is generated by describing the digits of the previous term. 🔹 Approach: Used recursion to generate the previous sequence (n-1) and built the current one by counting consecutive identical digits. Utilized StringBuilder for efficient string formation during traversal. 🔹 Key Learning: Improved recursion and pattern recognition skills. Practiced string manipulation and efficient concatenation. Understood how to construct sequences based on descriptive logic. 🔹 Complexity: Time: O(m) per level (m = length of previous term) Space: O(n) due to recursion depth #100DaysOfCode #LeetCode #Java #Recursion #Strings #ProblemSolving #DSA #CodingPatterns #Motivation #descipline
To view or add a comment, sign in
-
-
💻 Strengthening Problem-Solving Skills with LeetCode (Java) Recently explored a few interesting problems that focused on string manipulation, array traversal, and text formatting — each reinforcing clarity and precision in algorithmic thinking: 🔹 Text Justification Implemented a custom text alignment algorithm that evenly distributes spaces between words to fit a given line width. Approach: Greedy + StringBuilder Time Complexity: O(n) 🔹 Two Sum II – Input Array Is Sorted Solved using a two-pointer technique to efficiently find pairs that add up to a target value in a sorted array. Approach: Two Pointers Time Complexity: O(n) 🔹 Is Subsequence Checked whether one string is a subsequence of another using linear traversal and pointer comparison. Approach: Two Pointers Time Complexity: O(n) 🔹 Valid Palindrome Validated alphanumeric palindromes by filtering characters and comparing from both ends. Approach: String cleaning + two-pointer comparison Time Complexity: O(n) These problems helped sharpen my logic-building process and improved my confidence in designing efficient, readable solutions. #LeetCode #Java #ProblemSolving #DSA #Algorithms #Coding #SoftwareEngineering
To view or add a comment, sign in
-
💻 Strengthening My Algorithmic Skills with LeetCode (Java) Recently solved a few problems focusing on string manipulation and pattern-based logic, which helped me improve both problem decomposition and implementation clarity: 🔹 Zigzag Conversion Implemented a pattern-based traversal to simulate zigzag text arrangement across multiple rows. Approach: Row-by-row traversal Time Complexity: O(n) 🔹 Find the Index of the First Occurrence in a String (strStr) Developed a substring matching solution using a straightforward iterative comparison. Approach: Sliding window Time Complexity: O(n × m) 🔹 Reverse Words in a String Solved by splitting the input string, trimming spaces, and reconstructing it in reverse order. Approach: String split + reverse iteration Time Complexity: O(n) These problems helped strengthen my understanding of string operations, pattern logic, and efficient iteration techniques. #LeetCode #Java #DSA #ProblemSolving #Algorithms #Coding #SoftwareEngineering
To view or add a comment, sign in
-
💻 Enhancing Problem-Solving Skills with LeetCode (Java) Recently solved a couple of fundamental algorithmic problems that helped strengthen my understanding of two-pointer techniques, array manipulation, and writing efficient solutions. 🔹 Container With Most Water Implemented an optimised two-pointer approach to find the maximum water area between vertical lines. Instead of checking every pair (which would be O(n²)), the solution smartly moves the pointer at the shorter height inward to explore potentially larger areas. Approach: Two Pointers, Greedy Time Complexity: O(n) Space Complexity: O(1) 🔹 3Sum Solved the classic triplet-finding challenge by sorting the array and using two pointers to efficiently search for combinations that sum to zero. Also handled duplicates to avoid repeated triplets. Approach: Sorting + Two Pointers Time Complexity: O(n²) Space Complexity: O(1) (excluding output list) These problems helped sharpen my understanding of pointer movement, edge-case management, and designing clean, efficient solutions. #LeetCode #Java #Algorithms #DSA #Coding #ProblemSolving #SoftwareEngineering #LearningJourney
To view or add a comment, sign in
Explore related topics
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