How to find all anagrams in a string using Java

🚀 Another good one of the Day 43 of #100DaysOfCode 💻🔥 🔹 Problem: Find All Anagrams in a String 🎯 You’re given two strings s and p. The goal is to find all starting indices of p’s anagrams in s. 💡 My Intuition: Think of it like sliding a window over s while keeping track of character frequencies. If the frequency of characters inside the current window matches that of p, we’ve found an anagram. We maintain two arrays of size 26 (for each lowercase letter): arr → frequency of chars in p arr2 → frequency of chars in current window of s We keep sliding the window of size p.length() and compare both arrays at each step. 🧠 Key takeaway: Sliding window + frequency matching = powerful combo for string problems! It improves your intuition for optimizing brute-force solutions efficiently. 💪 #100DaysOfCode #LeetCode #DSA #Java #CodingJourney #ProblemSolving #KeepLearning

  • text

To view or add a comment, sign in

Explore content categories