Sub | Function to return the count of sub - strings starting from startIndex that are also the prefixes of string ; Function to return the count of all possible sub - strings of string that are also the prefixes of string ; If current character is equal to the starting character of str ; Driver Code ; Function Call
def subStringsStartingHere ( string , n , startIndex ) : NEW_LINE INDENT count = 0 NEW_LINE i = startIndex + 1 NEW_LINE while ( i <= n ) : NEW_LINE INDENT if string . startswith ( string [ startIndex : i ] ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT i += 1 NEW_LINE DEDENT return count NEW_LINE DEDENT def countSubStrings ( string , n ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if string [ i ] == string [ 0 ] : NEW_LINE INDENT count += subStringsStartingHere ( string , n , i ) NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT string = " ababc " NEW_LINE n = len ( string ) NEW_LINE print ( countSubStrings ( string , n ) ) NEW_LINE DEDENT