Solved "Find All Anagrams in a String" on LeetCode using sliding window and frequency comparison.

Day 25 of #100DaysOfCode Today I tackled the “Find All Anagrams in a String” problem on LeetCode — a great challenge that builds directly on the concept of sliding window and frequency comparison. 🧩 Problem Summary: Given two strings s and p, the task is to find all start indices in s where an anagram of p appears as a substring. At first, it might look similar to the “Permutation in String” problem — and that’s exactly the connection! The difference here is that instead of just checking if such a substring exists, we need to find all of them. ⚙️ Intuitive Approach: 1. Count character frequencies for p. 2. Use a sliding window over s of size equal to p.length(). 3. Maintain a frequency map for the current window and compare it with p’s frequency map. 4. Every time the maps match → we’ve found an anagram’s starting index. This problem reinforced how powerful the sliding window + frequency array technique can be when dealing with substring-based string problems. Each problem I solve reminds me that mastering patterns is far more valuable than memorizing solutions. #LeetCode #C++ #DSA #ProblemSolving #CodingJourney #100DaysOfCode

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories