text: Check if end of given Binary string can be reached by choosing jump value in between given range | C # program for the above approach ; Function to check if it is possible to reach the end of the binary string using the given jumps ; Stores the DP states ; Initial state ; Stores count of indices from which it is possible to reach index i ; Traverse the given string ; Update the values of pre accordingly ; If the jump size is out of the range [ L , R ] ; Return answer ; Driver Code
code: using System ; public class GFG { static int canReach ( String s , int L , int R ) { int [ ] dp = new int [ s . Length ] ; dp [ 0 ] = 1 ; int pre = 0 ; for ( int i = 1 ; i < s . Length ; i ++ ) { if ( i >= L ) { pre += dp [ i - L ] ; } if ( i > R ) { pre -= dp [ i - R - 1 ] ; } if ( pre > 0 && s [ i ] == '0' ) dp [ i ] = 1 ; else dp [ i ] = 0 ; } return dp [ s . Length - 1 ] ; } public static void Main ( ) { String S = "01101110" ; int L = 2 , R = 3 ; if ( canReach ( S , L , R ) == 1 ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }