Given a word and a text, return the count of the occurrences of anagrams of the word in the text(For eg: anagrams of word for are for, ofr, rof etc.))
Input : forxxorfxdofr for Output : 3 Explanation : Anagrams of the word for - for, orf, ofr appear in the text and hence the count is 3. Input : aabaabaa aaba Output : 4 Explanation : Anagrams of the word aaba - aaba, abaa each appear twice in the text and hence the count is 4.
A simple approach is to traverse from start of the string considering substrings of length equal to the length of the given word and then check if this substring has all the characters of word.
An Efficient Solution is to use count array to check for anagrams, we can construct current count window from previous window in O(1) time using sliding window concept.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count occurrences of a word in string
- Count of occurrences of a "1(0+)1" pattern in a string
- Count occurrences of a substring recursively
- Count of anagrams of each string in an array present in another array
- Count occurrences of a sub-string with one variable character
- Count occurrences of elements of list in Java
- Count occurrences of a character in a repeated string
- Count of occurrences of each prefix in a string using modified KMP algorithm
- Count subsequences in first string which are anagrams of the second string
- Count occurrences of a string that can be constructed from another given string
- Check if two strings are k-anagrams or not
- Number of index pairs such that s[i] and s[j] are anagrams
- Check if all levels of two trees are anagrams or not
- Given a sequence of words, print all anagrams together using STL
- Project Idea | (A Game of Anagrams )
- Find the word with most anagrams in a given sentence
- Check whether two strings are anagrams of each other using unordered_map in C++
- Given a sequence of words, print all anagrams together | Set 1
- Given a sequence of words, print all anagrams together | Set 2
- Print all pairs of anagrams in a given array of strings
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : nidhi_biet