Find the arrangement of queue at given time | prints the arrangement at time = t ; Checking the entire queue for every moment from time = 1 to time = t . ; If current index contains ' B ' and next index contains ' G ' then swap ; Driver code
< ? php function solve ( $ n , $ t , $ s ) { for ( $ i = 0 ; $ i < $ t ; $ i ++ ) { for ( $ j = 0 ; $ j < $ n - 1 ; $ j ++ ) { if ( $ s [ $ j ] == ' B ' && $ s [ $ j + 1 ] == ' G ' ) { $ temp = $ s [ $ j ] ; $ s [ $ j ] = $ s [ $ j + 1 ] ; $ s [ $ j + 1 ] = $ temp ; $ j ++ ; } } } echo ( $ s ) ; } $ n = 6 ; $ t = 2 ; $ s = " BBGBBG " ; solve ( $ n , $ t , $ s ) ; ? >