human
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"
How can the above be solved in Python?
assistant
#Here is code to count unique substrings of a string S present in a wraparound string and the other steps required.
 def findSubstringInWraproundString ( p ) :
	ans = 0
	curLen = 0
	arr = [ 0 ] * 26
	for i in range ( 0 , len ( p ) ) :
		curr = ord ( p [ i ] ) - ord ( ' a ' )
		if ( i > 0 and ( ord ( p [ i - 1 ] ) != ( ( curr + 26 - 1 ) % 26 + ord ( ' a ' ) ) ) ) :
			curLen = 0
		curLen += 1
		if ( curLen > arr [ curr ] ) :
			ans += ( curLen - arr [ curr ] )
			arr [ curr ] = curLen
	print ( ans )
p = " zab "
findSubstringInWraproundString ( p )