Check if it is possible to get back to 12 '0 clock only by adding or subtracting given seconds | Function to check all combinations ; Generate all power sets ; Check for every combination ; Store sum for all combinations ; Check if jth bit in the counter is set If set then print jth element from set ; $sum += $a [ $j ] ; if set then consider as ' + ' ; $sum -= $a [ $j ] ; else consider as ' - ' ; If we can get back to 0 ; Driver Code
< ? php function checkCombinations ( $ a , $ n ) { $ pow_set_size = pow ( 2 , $ n ) ; for ( $ counter = 0 ; $ counter < $ pow_set_size ; $ counter ++ ) { $ sum = 0 ; for ( $ j = 0 ; $ j < $ n ; $ j ++ ) { if ( $ counter & ( 1 << $ j ) ) else } if ( $ sum % ( 24 * 60 ) == 0 ) return true ; } return false ; } $ a = array ( 60 , 60 , 120 ) ; $ n = sizeof ( $ a ) ; if ( checkCombinations ( $ a , $ n ) ) echo " YES " ; else echo " NO " ; ? >