Maximum length substring with highest frequency in a string | function to return maximum occurred substring of a string ; size of string ; to store maximum frequency ; To store string which has maximum frequency ; return substring which has maximum freq ; Driver code ; Function call
def MaxFreq ( s ) : NEW_LINE INDENT n = len ( s ) NEW_LINE m = dict ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT string = ' ' NEW_LINE for j in range ( i , n ) : NEW_LINE INDENT string += s [ j ] NEW_LINE if string in m . keys ( ) : NEW_LINE INDENT m [ string ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT m [ string ] = 1 NEW_LINE DEDENT DEDENT DEDENT maxi = 0 NEW_LINE maxi_str = ' ' NEW_LINE for i in m : NEW_LINE INDENT if m [ i ] > maxi : NEW_LINE INDENT maxi = m [ i ] NEW_LINE maxi_str = i NEW_LINE DEDENT elif m [ i ] == maxi : NEW_LINE INDENT ss = i NEW_LINE if len ( ss ) > len ( maxi_str ) : NEW_LINE INDENT maxi_str = ss NEW_LINE DEDENT DEDENT DEDENT return maxi_str NEW_LINE DEDENT string = " ababecdecd " NEW_LINE INDENT print ( MaxFreq ( string ) ) NEW_LINE DEDENT