Count strings that end with the given pattern | Function that return true if str1 ends with pat ; Pattern is larger in length than the str1ing ; We match starting from the end while patLen is greater than or equal to 0. ; If at any index str1 doesn 't match  with pattern ; If str1 ends with the given pattern ; Function to return the count of required str1ings ; If current str1ing ends with the given pattern ; Driver code
def endsWith ( str1 , pat ) : NEW_LINE INDENT patLen = len ( pat ) NEW_LINE str1Len = len ( str1 ) NEW_LINE if ( patLen > str1Len ) : NEW_LINE INDENT return False NEW_LINE DEDENT patLen -= 1 NEW_LINE str1Len -= 1 NEW_LINE while ( patLen >= 0 ) : NEW_LINE INDENT if ( pat [ patLen ] != str1 [ str1Len ] ) : NEW_LINE INDENT return False NEW_LINE DEDENT patLen -= 1 NEW_LINE str1Len -= 1 NEW_LINE DEDENT return True NEW_LINE DEDENT def countOfstr1ings ( pat , n , sArr ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( endsWith ( sArr [ i ] , pat ) == True ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT pat = " ks " NEW_LINE n = 4 NEW_LINE sArr = [ " geeks " , " geeksforgeeks " , " games " , " unit " ] NEW_LINE print ( countOfstr1ings ( pat , n , sArr ) ) NEW_LINE