Maximum number of 0 s that can be flipped such that Array has no adjacent 1 s | Java program for the above approach ; Maximum number of 0 s that can be replaced by 1 ; Check for three consecutive 0 s ; Flip the bit ; Increase the count ; Driver code
public class geeks { public static int canReplace ( int [ ] array ) { int i = 0 , count = 0 ; while ( i < array . length ) { if ( array [ i ] == 0 && ( i == 0 array [ i - 1 ] == 0 ) && ( i == array . length - 1 array [ i + 1 ] == 0 ) ) { array [ i ] = 1 ; count ++ ; } i ++ ; } return count ; } public static void main ( String [ ] args ) { int [ ] array = { 1 , 0 , 0 , 0 , 1 } ; System . out . println ( canReplace ( array ) ) ; } }