Count strings that end with the given pattern | C # implementation of the approach ; Function that return true if str ends with pat ; Pattern is larger in length than the string ; We match starting from the end while patLen is greater than or equal to 0. ; If at any index str doesn 't match  with pattern ; If str ends with the given pattern ; Function to return the count of required strings ; If current string ends with the given pattern ; Driver code
using System ; class GFG { static bool endsWith ( string str , string pat ) { int patLen = pat . Length ; int strLen = str . Length ; if ( patLen > strLen ) return false ; patLen -- ; strLen -- ; while ( patLen >= 0 ) { if ( pat [ patLen ] != str [ strLen ] ) return false ; patLen -- ; strLen -- ; } return true ; } static int countOfStrings ( string pat , int n , string [ ] sArr ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( endsWith ( sArr [ i ] , pat ) ) count ++ ; return count ; } public static void Main ( ) { string pat = " ks " ; int n = 4 ; string [ ] sArr = { " geeks " , " geeksforgeeks " , " games " , " unit " } ; Console . WriteLine ( countOfStrings ( pat , n , sArr ) ) ; } }