Print n 0 s and m 1 s such that no two 0 s and no three 1 s are together | Function to print the required pattern ; When condition fails ; When m = n - 1 ; Driver code
< ? php function printPattern ( $ n , $ m ) { if ( $ m > 2 * ( $ n + 1 ) $ m < $ n - 1 ) { echo ( " - 1" ) ; } else if ( abs ( $ n - $ m ) <= 1 ) { while ( $ n > 0 && $ m > 0 ) { System . out . print ( "01" ) ; $ n -- ; $ m -- ; } if ( $ n != 0 ) { echo ( "0" ) ; } if ( $ m != 0 ) { echo ( "1" ) ; } } else { while ( $ m - $ n > 1 && $ n > 0 ) { echo ( "110" ) ; $ m = $ m - 2 ; $ n = $ n - 1 ; } while ( $ n > 0 ) { echo ( "10" ) ; $ n -- ; $ m -- ; } while ( $ m > 0 ) { echo ( "1" ) ; $ m -- ; } } } $ n = 4 ; $ m = 8 ; printPattern ( $ n , $ m ) ; ? >