Minimum number of elements to add to make median equals x | Returns count of elements to be added to make median x . This function assumes that a [ ] has enough extra space . ; to sort the array in increasing order . ; Driver code
< ? php function minNumber ( $ a , $ n , $ x ) { sort ( $ a ) ; $ k ; for ( $ k = 0 ; $ a [ ( $ n - 1 ) / 2 ] != $ x ; $ k ++ ) { $ a [ $ n ++ ] = $ x ; sort ( $ a ) ; } return $ k ; } $ x = 10 ; $ a = array ( 10 , 20 , 30 ) ; $ n = 3 ; echo minNumber ( $ a , $ n , $ x ) , " STRNEWLINE " ; ? >