Largest sub | C # implementation of the approach ; Function to return the largest substring divisible by 2 ; While the last character of the string is '1' , pop it ; If the original string had no '0' ; Driver code
using System ; class GFG { static string largestSubStr ( string s ) { while ( s . Length != 0 && s [ s . Length - 1 ] == '1' ) s = s . Substring ( 0 , s . Length - 1 ) ; if ( s . Length == 0 ) return " - 1" ; else return s ; } public static void Main ( ) { string s = "11001" ; Console . WriteLine ( largestSubStr ( s ) ) ; } }