dev-resources.site
for different kinds of informations.
Find all anagrams in the string[Fixed Window pattern]
Published at
1/4/2025
Categories
fixedwindow
twopointer
dsa
leetcode
Author
prashantrmishra
Author
15 person written this
prashantrmishra
open
Problem
TC:O(n)
SC:(k) is no. of substrings(anagrams) + O(1) for using constant space array of size 26
class Solution {
public List<Integer> findAnagrams(String s, String p) {
Map<Character,Integer> map = new HashMap<>();
int arrp[] = new int[26];
for(int i = 0;i<p.length();i++) arrp[p.charAt(i)-'a']++;
int arrs[] = new int[26];
List<Integer> result = new ArrayList<>();
int left =0,right = 0;
while(right<s.length()){
if(right-left+1< p.length()){
arrs[s.charAt(right)-'a']++;
right++;
}
else{
arrs[s.charAt(right)-'a']++;
right++;
if(check(arrp,arrs)) result.add(left);
arrs[s.charAt(left)-'a']--;
left++;
}
}
return result;
}
public boolean check(int a[], int b[]){
for(int i =0;i<26;i++){
if(a[i]!=b[i]) return false;
}
return true;
}
}
leetcode Article's
30 articles in total
Neetcode Roadmap Part 1
read article
2429. Minimize XOR
read article
A tΓ©cnica dos dois ponteiros
read article
2657. Find the Prefix Common Array of Two Arrays
read article
Time Complexity, Big-O for Beginners
read article
LeetCode Challenge: 383. Ransom Note - JavaScript Solution π
read article
3223. Minimum Length of String After Operations
read article
Leet code
read article
2116. Check if a Parentheses String Can Be Valid
read article
LeetCode Challenge: 73. Set Matrix Zeroes - JavaScript Solution π
read article
LeetCode Challenge: 290. Word Pattern - JavaScript Solution π
read article
LeetCode Challenge: 205. Isomorphic Strings - JavaScript Solution π
read article
Leetcode: 73 Set Matrix Zeroes
read article
LeetCode Challenge: 36.Valid Sudoku - JavaScript Solution π
read article
Count prefix and suffix I and II
read article
Leetcode Blind 75
read article
Rabin Karp (hashing) String pattern matching
read article
Leetcode β 2942. Find Words Containing Character
read article
Automating Your LeetCode Journey: Building an Enterprise-Grade LeetCode to GitHub Sync System
read article
Understanding the XOR Operator: A Powerful Tool in Computing
read article
Kadane's Algorithm: Leetcode 53 Maximum subarray
read article
1768. Merge Strings Alternately
read article
Find all anagrams in the string[Fixed Window pattern]
currently reading
No of ways to split Array
read article
Leetcode β 3289. The Two Sneaky Numbers of Digitville
read article
Range sum query 2D - Immutable
read article
Range Sum Query - Immutable
read article
Count vowel strings in ranges
read article
Yay! Reached 1035+ days Daily Coding Streak on Leetcode!
read article
Leetcode 75. Sort Colors
read article
Featured ones: