Traverse the input string again to find minimum number of flips
str . split ( ' ' ) . forEach ( x => { count0 -= ( x == ' ' ) ; count1 += ( x == ' ' ) ; res = Math . min ( res , count1 + count0 ) ; } ) ; return res ; }