Day 27 of 30-day Coding Sprint 76. Minimum Window Substring - The Goal: Find the smallest substring in s that contains all characters of t (including duplicates). - The Strategy: Expand & Contract - Preprocessing: Build a frequency map (using a 256-size array) for all characters in t. - Expansion (r pointer): Move the right pointer to expand the window. If the current character is part of t and we still need more of it, increment our count. - Contraction (l pointer): Once count == m (meaning the window is "valid"), try to shrink it from the left to find the minimum possible length. - The "Squeeze": As we move l, we update our frequency map. If moving l causes us to lose a required character from t, the window becomes invalid, and we go back to expanding. Result: Efficient O(N + M) time complexity and O(256) space. #30DaysOfCode #DSASprint #LeetCode #JavaScript #SlidingWindow #HardProblem #Algorithms #Consistency
30-Day Coding Sprint: Minimum Window Substring Algorithm
More Relevant Posts
-
🚀 LeetCode Problem Solved: Rotate Image (Matrix Rotation) Today I practiced an interesting array/matrix problem: Rotate Image. 📌 Problem: Given an n × n matrix, rotate the image 90° clockwise in-place without using another matrix. Example: Input [ [1,2,3], [4,5,6], [7,8,9] ] Output [ [7,4,1], [8,5,2], [9,6,3] ] 💡 Key Idea: Instead of creating a new matrix, we can solve it in two steps: 1️⃣ Transpose the matrix (swap rows and columns) 2️⃣ Reverse each row This transforms the matrix into a 90° clockwise rotated image efficiently. ⚡ Time Complexity: O(n²) 📦 Space Complexity: O(1) (In-place) 🎯 Practicing problems like this helps strengthen understanding of matrix manipulation and in-place algorithms, which are very common in coding interviews. #LeetCode #DSA #JavaScript #CodingPractice #SoftwareDeveloper #Programming #TechLearning
To view or add a comment, sign in
-
-
🧠 Day 178 — Next Greater Element 📈 Today I revised one of the most important stack pattern problems in DSA: Next Greater Element. The goal is straightforward but very useful: ✔ For every element, find the next greater element on its right ✔ If no greater element exists → return -1 This problem is a great example of combining: • Stacks • Efficient traversal techniques • Hash map lookups for fast queries Understanding this pattern unlocks solutions to many other problems like Daily Temperatures, Stock Span, and Largest Rectangle in Histogram. 🚀 DSA Journey Update Slowly building strong foundations in Stacks, Dynamic Programming, and Trees. Consistency is the real game. #DSA #Stacks #MonotonicStack #JavaScript #CodingJourney #LeetCode #ProblemSolving #ConsistencyWins
To view or add a comment, sign in
-
-
📌 #65 DailyLeetCodeDose Today's problem: 19. Remove Nth Node From End of List – 🟡 Medium Here I used a similar idea to one of the previous problems I solved – Floyd's Cycle Detection. Using two pointers allows us to solve the problem in a single pass through the linked list. First, the fast pointer moves n steps ahead. After that, both fast and slow pointers move together until fast reaches the end of the list. At that moment, the slow pointer will be right before the node that needs to be removed. This approach lets us remove the target node in O(n) time and O(1) space. Easy :) https://lnkd.in/eZvmFHfj #DailyLeetCodeDose #LeetCode #JavaScript #Algorithms #ProblemSolving #Coding
To view or add a comment, sign in
-
-
It's 5:45 am & I am still looking at my dreams. Today[2/28/2026] is day 23 of learning javascript Today & tommorow i will learn are: 1. Difference between let, const & var 2. How to use the default parameter 3. Template string, Multiline string, Dynamic string 4. Arrow Function Syntax, params 5. Spread Operator, Array Max, Copy Arrays 6. Object & Array destructuring 7. Keys, Values, Entries, Delete, Seal, Freeze 8. Accessing Object Data: Nested Object, Optional Chaining 9. Looping Object 10. Primitive Type, Non Primitive Type 11. Null Vs Undefines 12. Truthy & Falsy Values 13. ==, === , implicit conversion 14. Block Scope, Global Scope, Simple Unders. of Hoisting 15. Closure 16. Callback Function & pass different function 17. Function Arguments, pass by ref. pass by value 18. Map, ForEach 19. Filter, Find, Reduce #letsconnect #programmer #frontenddeveloper #mernstakedeveloper #Coding
To view or add a comment, sign in
-
🚀 𝗡𝗲𝘄 𝗣𝗥 𝗠𝗲𝗿𝗴𝗲𝗱 I recently tackled a fun logical puzzle: how to move all zeroes to the end of an array while maintaining the relative order of the non-zero elements. This challenge, which I've documented in my latest PR (https://lnkd.in/dSXWnSES), really tested my ⚙️ 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵 to array manipulation. My solution involved iterating through the array and using a pointer to keep track of the position where the next non-zero element should be placed. This allowed me to effectively "compress" the non-zero elements to the front, implicitly leaving zeroes at the end. During the process, I leaned on dry runs to trace the array's state and visualize the pointer movements. When I hit a snag, the debugger was invaluable for stepping through the logic line by line and understanding exactly where my assumptions were off. A key takeaway for me was the power of in-place modification and how a well-placed pointer can simplify array problems significantly. How do you ⚙️ 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵 similar array manipulation challenges? Share your strategies below! 📦 Repo: https://lnkd.in/dSXWnSES #ArrayManipulation #JavaScript #Algorithms #ProblemSolving #CodingChallenge #DataStructures #InPlaceAlgorithms #LogicalReasoning #SoftwareDevelopment #LeetCodeStyle
To view or add a comment, sign in
-
-
Day 29 of 30-day Coding Sprint Today's problem, Time Needed to Buy Tickets, is a perfect example of how you can move from a "literal" simulation to a "mathematical" observation. Approach 1: Simulation Using a Queue - The Logic: We treat the problem exactly as described. We use a queue to store pairs of [tickets_needed, original_index]. - The Flow: 1. Take the person from the front. 2. Subtract 1 from their ticket count and increment time. 3. If they still need tickets, push them back to the end of the queue. 4. Stop as soon as the person at original_index === k has 0 tickets left. - Pros: Very easy to visualize and "act out" the problem. - Cons: Higher time complexity O(n * max_tickets). Approach 2: The Optimized One-Pass The Logic: Instead of simulating every second, we calculate how many tickets each person actually buys before the person at index k finishes. The Observation: People at or before index k: They can buy at most tickets[k] tickets. People after index k: They can buy at most tickets[k] - 1 tickets (because once person k buys their last ticket, the clock stops immediately). Result: Clean O(N) time and O(1) space. #30DaysOfCode #DSASprint #LeetCode #JavaScript #Queues #Simulation #Optimization #Consistency
To view or add a comment, sign in
-
-
📌 #57 DailyLeetCodeDose Today's problem: 221. Maximal Square – 🟡 Easy The very first, naive solution that usually comes to mind is to simply compute the size of every square encountered in the matrix. However, this approach has a major drawback: we end up traversing the same matrix elements many times. The larger the matrix is, the more noticeable and costly this problem becomes. Once we introduce memoization – storing the maximum square size that can be built starting from the current cell with given coordinates – and reuse these values, the solution immediately becomes significantly faster. In my case, the time complexity improved from O(M · N · min(M, N)) 👉 O(M · N), and the actual runtime dropped from 1561 ms 👉 11 ms So, guys, don't just make it work – make it right. https://lnkd.in/eeppiXXG #DailyLeetCodeDose #LeetCode #JavaScript #Algorithms #ProblemSolving #Coding
To view or add a comment, sign in
-
-
Solved Linked List Cycle II using Floyd’s Cycle Detection Algorithm (Tortoise and Hare). The approach uses two pointers moving at different speeds to first detect the cycle and then identify the exact node where the cycle begins. Once the pointers meet, resetting one pointer to the head and moving both one step at a time leads them to the cycle start node. Key Takeaways: Efficient cycle detection in linked lists O(n) time complexity O(1) space complexity Classic two-pointer technique #DataStructures #Algorithms #LinkedList #JavaScript #LeetCode #ProblemSolving #CodingJourney #SoftwareEngineering
To view or add a comment, sign in
-
-
JavaScript’s sort() can silently break your algorithms. I was solving LeetCode #350 (Intersection of Two Arrays II) using the two-pointer approach and hit an unexpected issue. I sorted the arrays like this: nums.sort() It looked fine… until it wasn’t. Example: [1, 2, 10, 5].sort() // → [1, 10, 2, 5] Why? Because JavaScript sorts lexicographically (as strings) by default. So the engine actually compares: "1", "10", "2", "5" Correct numeric sorting requires a comparator: nums.sort((a, b) => a - b) Without this, algorithms that rely on sorted arrays (binary search, two-pointer techniques, etc.) can produce incorrect results. #JavaScript #WebDevelopment #Programming #CodingTips #LeetCode #Algorithms #SoftwareEngineering #FrontendDevelopment
To view or add a comment, sign in
-
-
🚀 DSA Daily Challenge – Day 18: Longest Substring Without Repeating Characters (Medium) 🧠 A classic sliding window problem from LeetCode 3, perfect for mastering hashing + two-pointer/window techniques. 🔍 Problem Recap Given a string s, find the length of the longest substring without repeating characters. Substring must have unique characters Return max length 💡 Core Idea Instead of checking every substring (O(n²)), we can use sliding window + HashSet: 1️⃣ Use two pointers: left → start of current substring right → end of current substring 2️⃣ Maintain a HashSet of characters in current window 3️⃣ Iterate right: If s[right] exists in set → remove s[left] and move left forward Else → add s[right] to set and update maxLength This ensures every character is in the window at most once, giving linear time complexity. 🧠 Why This Works Sliding window ensures no repeated characters HashSet gives O(1) lookup Each character is added/removed at most once → O(n) time Space complexity → O(min(n, charset)) 🧩 Dry Run Example String: "abcabcbb" Window expands: "a" → "ab" → "abc" → "bca" → "cab" Max substring without repeats → "abc" → length = 3 ⚡ Pattern Connection Sliding window / two pointers Hashing for uniqueness Converting brute-force substring checking (O(n²)) → O(n) solution Builds intuition for subarray/subsequence problems #DSA #LeetCode #Day18 #Java #SlidingWindow #HashSet #Strings #CodingInterview #ProblemSolving #100DaysOfCode #DataStructures #InterviewPrep #Algorithm #MediumLevel #ProgrammingTips #CodingChallenge #LongestSubstring #NoRepeats #OptimizedCode
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