Minimum removal of consecutive similar characters required to empty a Binary String | Java program for the above approach ; Function to find minimum steps to make the String empty ; Stores the modified String ; Size of String ; Removing subString of same character from modified String ; Print the minimum steps required ; Driver Code ; Given String S ; Function Call
import java . util . * ; class GFG { static void minSteps ( String S ) { String new_str = " " ; int N = S . length ( ) ; int i = 0 ; while ( i < N ) { new_str += S . charAt ( i ) ; int j = i ; while ( i < N && S . charAt ( i ) == S . charAt ( j ) ) ++ i ; } System . out . print ( ( int ) Math . ceil ( ( new_str . length ( ) + 1 ) / 2.0 ) ) ; } public static void main ( String [ ] args ) { String S = "0010100" ; minSteps ( S ) ; } }