Count unique substrings of a string S present in a wraparound string | Function to find the count of non - empty substrings of p present in s ; Stores the required answer ; Stores the length of substring present in p ; Stores the current length of substring that is present in string s starting from each character of p ; Iterate over the characters of the string ; Check if the current character can be added with previous substring to form the required substring ; Increment current length ; To avoid repetition ; Update arr [ cur ] ; Print the answer ; Driver Code ; Function call to find the count of non - empty substrings of p present in s
def findSubstringInWraproundString ( p ) : NEW_LINE INDENT ans = 0 NEW_LINE curLen = 0 NEW_LINE arr = [ 0 ] * 26 NEW_LINE for i in range ( 0 , len ( p ) ) : NEW_LINE INDENT curr = ord ( p [ i ] ) - ord ( ' a ' ) NEW_LINE if ( i > 0 and ( ord ( p [ i - 1 ] ) != ( ( curr + 26 - 1 ) % 26 + ord ( ' a ' ) ) ) ) : NEW_LINE INDENT curLen = 0 NEW_LINE DEDENT curLen += 1 NEW_LINE if ( curLen > arr [ curr ] ) : NEW_LINE INDENT ans += ( curLen - arr [ curr ] ) NEW_LINE arr [ curr ] = curLen NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE DEDENT p = " zab " NEW_LINE findSubstringInWraproundString ( p ) NEW_LINE