Python | Count all prefixes in given string with greatest frequency
Given a string, print and count all prefixes in which first alphabet has greater frequency than second alphabet.
Take two alphabets from the user and compare them. The prefixes in which the alphabet given first has greater frequency than the second alphabet, such prefixes are printed, else the result will be 0.
Input : string1 = "geek", alphabet1 = "e", alphabet2 = "k" Output : ge gee geek 3 Input : string1 = "geek", alphabet1 = "k", alphabet2 = "e" Output : 0
Approach : Take an empty string to store the string values of all the prefixes formed. Then check for the alphabet with greater frequency than the second alphabet. If no such case is found then the result will be 0 prefixes.
Below is the implementation :
gee geek geeks geeksf geeksfo geeksfor geeksforge geeksforgee geeksforgeek geeksforgeeks 10
Time Complexity: O(N), where N is the length of the string
Auxiliary Space: O(N)