Minimum Window Substring in TypeScript using Sliding Window and ASCII Map

View profile for Kannan Durvas

Software Developer at Mirchi-Lime | SQL, Zoho Analytics, Zoho Creator, Python, JavaScript, TypeScript, Node.js | Building Scalable Solutions

🧠 LeetCode Algorithm - Minimum Window Substring 📌 Problem: Given two strings s and t, return the minimum window in s which contains all the characters in t. 🔍 Approach: Sliding window + character count tracking using ASCII map. 🔍 Algorithm (Sliding Window + ASCII Map) 💡 Step-by-step logic: StepAction 1️⃣Build a frequency map of string t characters using ASCII (map[charCode]++) 2️⃣Use a sliding window with two pointers (left and right) 3️⃣Move right pointer to expand the window, decreasing map[charCode] 4️⃣When all chars from t are covered (count == 0), try to shrink from left 5️⃣Update minLen and start if a smaller window is found 6️⃣Return the substring from start to start + minLen 📈 Performance: ✅ Accepted in 9ms, beating 97.83% on runtime 📉 Memory usage: 59.05 MB, better than 78.93% 🧪 Tested on 268 cases 🔢 Example: s = "ADOBECODEBANC", t = "ABC" 🟢 Output: "BANC" #LeetCode #TypeScript #Coding #ProblemSolving #SoftwareDeveloper #Frontend #100DaysOfCode #KannanCodes #TwoPointers #Algorithms

  • graphical user interface, text, application, chat or text message

To view or add a comment, sign in

Explore topics