Minimize insertions required to make all characters of a given string equal | Java program to implement the above approach ; Function to calculate the minimum number of operations required to make all characters of the string same ; Stores count of operations ; Traverse the string ; Check if adjacent characters are same or not ; Increment count ; Print the count obtained ; Driver Code
import java . io . * ; import java . util . * ; class GFG { static void minOperations ( String S ) { int count = 0 ; for ( int i = 1 ; i < S . length ( ) ; i ++ ) { if ( S . charAt ( i ) != S . charAt ( i - 1 ) ) { count += 1 ; } } System . out . print ( count ) ; } public static void main ( String [ ] args ) { String S = "0101010101" ; minOperations ( S ) ; } }