human
Different substrings in a string that start and end with given strings | function to return number of different sub - strings.
initially our answer is zero ..
find the length of given strings.
currently make array and initially put zero ..
find occurrence of " a " and " b " in string " s ".
We use a hash to make sure that same substring is not counted twice ..
go through all the positions to find occurrence of " a " first ..
if we found occurrence of " a " ..
then go through all the positions to find occurrence of " b " ..
if we do found " b " at index j then add it to already existed substring ..
if we found occurrence of " b " ..
now add string " b " to already existed substring ..
If current substring is not included already ..
put any non negative integer to make this string as already existed ..
make substring null ..
return answer ..
Driver Code"
Solution in Python:
 ... Give me a code to different substrings in a string that start and end with given strings and the other steps required?
assistant
#Here is code to different substrings in a string that start and end with given strings and the other steps required.
 def numberOfDifferentSubstrings ( s , a , b ) :
	ans = 0
	ls = len ( s )
	la = len ( a )
	lb = len ( b )
	x = [ 0 ] * ls
	y = [ 0 ] * ls
	for i in range ( ls ) :
		if ( s [ i : la + i ] == a ) :
			x [ i ] = 1
		if ( s [ i : lb + i ] == b ) :
			y [ i ] = 1
	hash = [ ]
	curr_substr = " "
	for i in range ( ls ) :
		if ( x [ i ] ) :
			for j in range ( i , ls ) :
				if ( not y [ j ] ) :
					curr_substr += s [ j ]
				if ( y [ j ] ) :
					curr_substr += s [ j : lb + j ]
					if curr_substr not in hash :
						ans += 1
					hash . append ( curr_substr )
			curr_substr = " "
	return ans
if __name__ == " _ _ main _ _ " :
	s = " codecppforfood "
	begin = " c "
	end = " d "
	print ( numberOfDifferentSubstrings ( s , begin , end ) )