Check if it is possible to serve customer queue with different notes | Function that returns true is selling of the tickets is possible ; Nothing to return to the customer ; Check if 25 can be returned to customer . ; Try returning one 50 and one 25 ; Try returning three 25 ; If the loop did not break , all the tickets were sold ; Driver Code
< ? php function isSellingPossible ( $ n , $ a ) { $ c25 = 0 ; $ c50 = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ a [ $ i ] == 25 ) $ c25 ++ ; else if ( $ a [ $ i ] == 50 ) { $ c50 ++ ; if ( $ c25 == 0 ) break ; $ c25 -- ; } else { if ( $ c50 > 0 && $ c25 > 0 ) { $ c50 -- ; $ c25 -- ; } else if ( $ c25 >= 3 ) $ c25 -= 3 ; else break ; } } if ( $ i == $ n ) return true ; else return false ; } $ a = array ( 25 , 25 , 50 , 100 ) ; $ n = sizeof ( $ a ) ; if ( isSellingPossible ( $ n , $ a ) ) { echo " YES " ; } else { echo " NO " ; } ? >