Solved findSubstring with frequency maps on Day 29 of #100DaysOfCode

🚀 Day 29 of #100DaysOfCode — LeetCode + HackerRank Edition! Today’s challenge was all about precision and pattern matching — and I stuck to the essentials. 🔗 Problem: findSubstring(s, words) (LeetCode) 📌 Challenge: Given a string s and a list of words (all the same length), find all starting indices where the concatenation of all words appears exactly once and without overlap. 🔍 Approach: → Calculated the total length of the target substring using len(words[0]) * len(words) → Built a frequency map using Counter(words) → Used a sliding window of size total_len to scan through s → At each position, extracted word-sized chunks and tracked their frequency → Compared the seen map with the original word_count to validate matches → Appended valid starting indices to the result list 💡 What made it click: → Realized that permutations aren’t necessary — just match word frequencies → Stepping through s in word-sized chunks keeps the logic clean and efficient → Using Counter for both the target and current window made comparison seamless 📚 What I learned: ✅ Frequency maps are a powerful alternative to brute-force approaches ✅ Matching dictionaries directly (seen == word_count) is a validation trick ✅ Clean logic and early breaks make the code both readable and performant Have you solved findSubstring before? Did you go with permutations or lean into frequency maps like I did? Let’s swap strategies 💬 #Day29 #LeetCode #SlidingWindow #StringAlgorithms #Python #ProblemSolving #CleanCode #CodeEveryDay #LearnToCode #CodeNewbie #SoftwareEngineering #TechJourney #100DaysOfCode

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

To view or add a comment, sign in

Explore content categories