Given a string consisting of lower case English Alphabets. The task is to count the number of occurrences of the non-empty prefix which occurs the maximum number of times in the string as a substring.
Input : str = "abbcdabbcd" Output : 2 The prefix "abb" has maximum number of occurrences 2. Input : str = "abc" Output : 1
Approach: The idea is to observe that every prefix of the array must contain the first character of the string and each of it’s respective occurrences will also. Also the 1st character of a string is the minimum length prefix. So, the prefix with maximum number of occurrences will be the first character of the string itself. Therefore, the task now reduces to find the frequency of the first character in the given string.
Below is the implementation of the above approach:
- Find the maximum length of the prefix
- Maximum length prefix of one string that occurs as subsequence in another
- Count all elements in the array which appears at least K times after their first occurrence
- Strings from an array which are not prefix of any other string
- Index with Minimum sum of prefix and suffix sums in an Array
- Find the occurrence of the given binary pattern in the binary representation of the array elements
- Longest string in an array which matches with prefix of the given string
- Maximum subarray sum in array formed by repeating the given array k times
- Maximum value of arr[i] % arr[j] for a given array
- Find indices of all occurrence of one string in other
- Print characters and their frequencies in order of occurrence
- Program to count occurrence of a given character in a string
- Print characters having odd frequencies in order of occurrence
- Print characters having even frequencies in order of occurrence
- Find the maximum subarray XOR in a given array
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.