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
#include <bits/stdc++.h> NEW_LINE using namespace std ; string largestSubStr ( string s ) { while ( s . size ( ) and s [ s . size ( ) - 1 ] == '1' ) s . pop_back ( ) ; if ( s . size ( ) == 0 ) return " - 1" ; else return s ; } int main ( ) { string s = "11001" ; cout << largestSubStr ( s ) ; return 0 ; }