you give 0indexed binary string s represent sequence train car si 0 denote ith car contain illegal good si 1 denote ith car contain illegal goodsAs train conductor like rid car contain illegal good you follow operation number timesremove train car leave end ie remove s0 take 1 unit timeremove train car right end ie remove sslength 1 take 1 unit timeremove train car sequence take 2 unit timereturn minimum time remove car contain illegal goodsnote sequence car consider car contain illegal good Example 1input s 1100101output 5explanation one way remove car contain illegal good sequence remove car leave end 2 time Time take 2 1 2 remove car right end Time take 1 remove car contain illegal good find middle Time take 2this obtain total time 2 1 2 5 an alternative way remove car leave end 2 time Time take 2 1 2 remove car right end 3 time Time take 3 1 3this obtain total time 2 3 55 minimum time take remove car contain illegal good there way remove timeexample 2input s 0010output 2explanationone way remove car contain illegal good sequence remove car leave end 3 time Time take 3 1 3this obtain total time 3another way remove car contain illegal good sequence remove car contain illegal good find middle Time take 2this obtain total time 2another way remove car contain illegal good sequence remove car right end 2 time Time take 2 1 2 this obtain total time 22 minimum time take remove car contain illegal good there way remove time Constraints1 slength 2 105si 0 1