Queries to check if string B exists as substring in string A |  ; Dp Array ; String to character array ; initialize matrix with 1 ; for r from 1 to string length ; for c from 1 b string length ; For every query ; print true ; print false ; Driver Code
using System ; public class GFG { private static void substringCheck ( string stra , string strb , int [ ] query ) { int [ , ] matrix = new int [ strb . Length , stra . Length ] ; char [ ] charCrr = stra . ToCharArray ( ) ; char [ ] charRrr = strb . ToCharArray ( ) ; for ( int c = 0 ; c < stra . Length ; c ++ ) { if ( charRrr [ 0 ] == charCrr ) { matrix [ 0 , c ] = 1 ; } } for ( int r = 1 ; r < charRrr . Length ; r ++ ) { char ch = charRrr [ r ] ; for ( int c = 1 ; c < charCrr . Length ; c ++ ) { if ( ch == charCrr && matrix [ r - 1 , c - 1 ] == 1 ) { matrix [ r , c ] = 1 ; } } } foreach ( int q in query ) { int matLoc = ( q + ( strb . Length - 1 ) ) ; if ( matLoc >= stra . Length ) { Console . WriteLine ( false ) ; } else { if ( matrix [ strb . Length - 1 , matLoc ] == 1 ) { Console . WriteLine ( true ) ; } else { Console . WriteLine ( false ) ; } } } } public static void Main ( string [ ] args ) { string stra = " GeeksForGeeks " ; string strb = " Geeks " ; int [ ] query = { 0 , 5 , 8 } ; substringCheck ( stra , strb , query ) ; } }