Day 53/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Minimum Window Substring One of the most important sliding window problems. String properties: • We need a substring containing all characters of another string • Characters can repeat • The answer must be the smallest valid window Key idea: Use the sliding window technique with two pointers. Why? • Expanding the window helps include required characters • Shrinking the window helps find the minimum length • Efficiently balances both conditions Approach: • Store frequency of characters from string t • Use two pointers (left & right) to form a window • Expand right pointer to include characters • Decrease required count when a valid char is found • Once all chars are matched → try shrinking from left • Track the minimum window length during the process Time Complexity: O(n + m) Space Complexity: O(1) (constant for character set) Big takeaway: Sliding window is all about expand → satisfy → shrink → optimize. Sliding window concepts getting stronger day by day. 🔥 Day 53 done. #100DaysOfCode #LeetCode #DSA #Algorithms #SlidingWindow #Strings #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
Yogesh ..’s Post
More Relevant Posts
-
Day 44 of Daily DSA 🚀 Solved LeetCode 1572: Matrix Diagonal Sum ✅ Problem: Given a square matrix mat, return the sum of the matrix diagonals. Only include the sum of all the elements on the primary diagonal and all the elements on the secondary diagonal that are not part of the primary diagonal. Approach: Used a two-pointer technique to traverse both diagonals in a single pass. Steps: Initialize two pointers → start = 0, end = n-1 Traverse each row: Add mat[i][start] (primary diagonal) Add mat[i][end] (secondary diagonal) Move pointers: start++, end-- If matrix size is odd → add center element once ⏱ Complexity: • Time: O(n) • Space: O(1) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 46.53 MB Optimizing nested loops into a single pass can make your solution both cleaner and faster 💡 #DSA #LeetCode #Java #Arrays #Matrix #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 78 of #100DaysOfCode Solved 443. String Compression on LeetCode 🔗 🧠 Key Insight: We compress the array in-place by: 👉 Replacing consecutive characters with: char + count (if count > 1) Example: ["a","a","b","b","c","c","c"] → ["a","2","b","2","c","3"] ⚙️ Approach (Two Pointers): 1️⃣ Use two pointers: 🔹 i → iterate through array 🔹 idx → position to write compressed result 2️⃣ For each character: 🔹 Count consecutive occurrences using a loop 3️⃣ Write character: 🔹 chars[idx++] = ch 4️⃣ If count > 1: 🔹 Convert count to string 🔹 Add each digit to array 5️⃣ Continue until end 6️⃣ Return idx (new length) ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #Strings #TwoPointers #Array #Java #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
-
Day 55/100 | #100DaysOfDSA 🔄🧠 Today’s problem: Permutation in String A classic sliding window + frequency count problem. Core idea: We need to check if any permutation of s1 exists as a substring in s2. Approach: • Maintain a frequency array for s1 • Use a sliding window over s2 • Expand the window by moving right pointer • If frequency becomes invalid → shrink from left • If window size matches s1 → valid permutation found Key insight: Instead of generating all permutations (which is expensive), we match character counts dynamically. Time Complexity: O(n) Space Complexity: O(1) (fixed size array of 26) Big takeaway: Sliding window + frequency tracking is a powerful combo for substring problems. These pattern-based problems are getting sharper day by day. 🔥 Day 55 done. #100DaysOfCode #LeetCode #DSA #Algorithms #SlidingWindow #Strings #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 39 of Daily DSA 🚀 Solved LeetCode 1446: Consecutive Characters ✅ Problem: The power of a string is the maximum length of a non-empty substring that contains only one unique character. Given a string s, return its power. Rules: * Substring must be non-empty * Substring must contain only one unique character * Return the maximum such length Approach: Used a simple linear scan to track the current streak of consecutive identical characters and update the maximum. Steps: 1. Initialize max and count both to 1 2. Iterate from index 1 onwards 3. If current character equals previous → increment count 4. Else → reset count to 1 5. Update max at every step 6. Return max ⏱ Complexity: • Time: O(n) • Space: O(1) 📊 LeetCode Stats: • Runtime: 29 ms (Beats 2.02%) • Memory: 45.33 MB Sometimes the simplest sliding window — just two variables — is all you need to solve a problem cleanly. #DSA #LeetCode #Java #SlidingWindow #Strings #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 56/100 | #100DaysOfDSA 🧠⚡ Today’s problem: String Compression A clean in-place array manipulation problem. Core idea: Compress consecutive repeating characters and store the result in the same array. Approach: • Traverse the array using a pointer • Count consecutive occurrences of each character • Write the character to the array • If count > 1 → write its digits one by one • Move forward and repeat Key insight: We don’t need extra space — just carefully manage read & write pointers. Time Complexity: O(n) Space Complexity: O(1) Big takeaway: In-place algorithms require precise pointer control but give optimal space efficiency. Mastering these improves real-world memory optimization skills. 🔥 Day 56 done. #100DaysOfCode #LeetCode #DSA #Algorithms #Strings #TwoPointers #InPlace #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
🔄 Solved “Spiral Matrix”, a classic matrix traversal problem using boundary-based approach. ✦ What This Problem Taught Me: • How to traverse a 2D matrix layer by layer using boundaries • Effective use of four pointers (top, bottom, left, right) • Managing direction-based traversal (→ ↓ ← ↑) • Importance of shrinking boundaries after each iteration • Avoiding duplicate traversals using proper conditions • Strengthened understanding of 2D arrays and indexing 🚀 Problems like this show how controlling boundaries and direction can simplify complex matrix traversals into a clean O(m × n) solution. On to solving more matrix and pattern-based problems 💪🔥 #LeetCode #DSA #Matrix #TwoPointers #CodingJourney #ProblemSolving #Java #100DaysOfCode
To view or add a comment, sign in
-
-
✅ Solved LeetCode 217 — Contains Duplicate! Given an integer array nums, return true if any value appears at least twice. 🧠 My Approach: Sort + Linear Scan → Sort the array → adjacent duplicates are guaranteed to be neighbors → One pass to check if nums[i] == nums[i-1] → Time: O(n log n) | Space: O(1) 💡 Key Insight: Sorting brings duplicates side by side — no need for extra space like a HashSet. Trade time for space! ```java Arrays.sort(nums); for (int i = 1; i < nums.length; i++) { if (nums[i] == nums[i - 1]) return true; } return false; ``` 🔄 Alternative approaches: • HashSet → O(n) time, O(n) space • Brute force → O(n²) time (avoid!) Every problem teaches you a new trade-off. Keep grinding! 💪 #LeetCode #DSA #CodingInterview #Java #ProblemSolving #SoftwareEngineering #100DaysOfCode #Programming
To view or add a comment, sign in
-
-
Day 12 of #100DaysOfCode — Sliding Window Today, I worked on the problem “Max Consecutive Ones III” LeetCode. Problem Summary Given a binary array, the goal is to find the maximum number of consecutive 1s if you can flip at most k zeros. Approach At first glance, this problem looks like a brute-force or restart-based problem, but the optimal solution lies in the Sliding Window technique. The key idea is to maintain a window [i, j] such that: The number of zeros in the window does not exceed k Expand the window by moving j Shrink the window by moving i whenever the constraint is violated Instead of restarting the window when the condition breaks, we dynamically adjust it. Key Logic Traverse the array using pointer j Count the number of zeros in the current window If zeros exceed k, move pointer i forward until the window becomes valid again At every step, update the maximum window size Why This Works This approach ensures: Each element is processed at most twice Time Complexity: O(n) Space Complexity: O(1) The most important learning here is understanding how to dynamically adjust the window instead of resetting it, which is a common mistake while applying sliding window techniques. In sliding window problems, always focus on expanding and shrinking the window efficiently rather than restarting the computation. #100DaysOfCode #DSA #SlidingWindow #LeetCode #Java #ProblemSolving #CodingJourney #DataStructures #Algorithms
To view or add a comment, sign in
-
-
🚀 LeetCode Challenge 34/50 💡 Approach: Column Compression + Prefix Sum + TreeSet A true multi-technique Hard problem! Compress 2D matrix into 1D row sums, then use a TreeSet with prefix sums to efficiently find the maximum subarray sum ≤ k! 🔍 Key Insight: → Fix left and right column boundaries (O(cols²)) → Compress rows between boundaries into temp[] array → Now the problem reduces to: max subarray sum ≤ k in 1D! → Use prefix sum + TreeSet for O(n log n) per column pair → TreeSet.ceiling(prefixSum - k) finds the best previous prefix! 📈 Complexity: ❌ Brute Force → O(rows² × cols²) Time ✅ Compression + TreeSet → O(cols² × rows × log(rows)) Time This problem is a masterclass in problem reduction — turn 2D into 1D, then apply the right data structure. Three techniques, one elegant solution! 🎯 #LeetCode #DSA #TreeSet #PrefixSum #Java #ADA #PBL2 #LeetCodeChallenge #Day34of50 #CodingJourney #ComputerEngineering #AlgorithmDesign #HardLeetCode
To view or add a comment, sign in
-
-
Day 46/75 — Frequency of the Most Frequent Element Today’s problem was about maximizing the frequency of an element using at most k increments. Approach: • Sort the array • Use sliding window • Maintain sum of current window • Expand right pointer • Shrink window when operations exceed k Key logic: while ((long) nums[right] * (right - left + 1) - total > k) { total -= nums[left]; left++; } maxFreq = Math.max(maxFreq, right - left + 1); Time Complexity: O(n log n) (sorting) Space Complexity: O(1) Key Insight: Make all elements in window equal to the largest element — check if cost ≤ k. 46/75 🚀 #Day46 #DSA #SlidingWindow #TwoPointers #Java #Algorithms #LeetCode
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
Keep gng 💪🏻