Check if given words are present in a string | Helper Function to the Finding bigString ; Initialize leftBigIdx and rightBigIdx and leftSmallIdx variables ; Iterate until leftBigIdx variable reaches less than or equal to rightBigIdx ; Check if bigString [ leftBigIdx ] is not equal to smallString [ leftSmallIdx ] or Check if bigString [ rightBigIdx ] is not equal to smallString [ rightSmallIdx ] than return false otherwise increment leftBigIdx and leftSmallIdx decrement rightBigIdx and rightSmallIdx ; Function to the bigString ; iterate in the bigString ; Check if length of smallString + i is greater than the length of bigString ; call the function isInBigStringHelper ; Function to the multiStringSearch ; iterate in the smallString ; calling the isInBigString Function ; Driver code ; initialize string ; initialize vector string ; Function call ; Print answers ; Check if ans [ i ] is equal to 1 then Print true otherwise print false
def isInBigStringHelper ( bigString , smallString , startIdx ) : NEW_LINE INDENT leftBigIdx = startIdx NEW_LINE rightBigIdx = startIdx + len ( smallString ) - 1 NEW_LINE leftSmallIdx = 0 NEW_LINE rightSmallIdx = len ( smallString ) - 1 NEW_LINE while ( leftBigIdx <= rightBigIdx ) : NEW_LINE INDENT if ( bigString [ leftBigIdx ] != smallString [ leftSmallIdx ] or bigString [ rightBigIdx ] != smallString [ rightSmallIdx ] ) : NEW_LINE INDENT return False NEW_LINE DEDENT leftBigIdx += 1 NEW_LINE rightBigIdx -= 1 NEW_LINE leftSmallIdx += 1 NEW_LINE rightSmallIdx -= 1 NEW_LINE DEDENT return True NEW_LINE DEDENT def isInBigString ( bigString , smallString ) : NEW_LINE INDENT for i in range ( len ( bigString ) ) : NEW_LINE INDENT if ( i + len ( smallString ) > len ( bigString ) ) : NEW_LINE INDENT break NEW_LINE DEDENT if ( isInBigStringHelper ( bigString , smallString , i ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT def multiStringSearch ( bigString , smallStrings ) : NEW_LINE INDENT solution = [ ] NEW_LINE for smallString in smallStrings : NEW_LINE INDENT solution . append ( isInBigString ( bigString , smallString ) ) NEW_LINE DEDENT return solution NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str1 = " this ▁ is ▁ a ▁ big ▁ string " NEW_LINE substr = [ " this " , " yo " , " is " , " a " , " bigger " , " string " , " kappa " ] NEW_LINE ans = multiStringSearch ( str1 , substr ) NEW_LINE for i in range ( len ( ans ) ) : NEW_LINE INDENT if ( ans [ i ] == 1 ) : NEW_LINE INDENT print ( " true " , end = " ▁ " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " false " , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT