Median after K additional integers | Find median of array after adding k elements ; sorting the array in increasing order . ; printing the median of array . Since n + K is always odd and K < n , so median of array always lies in the range of n . ; driver program
function printMedian ( arr , n , K ) { arr . sort ( ) ; document . write ( arr [ Math . floor ( ( n + K ) / 2 ) ] ) ; } let arr = [ 5 , 3 , 2 , 8 ] ; let k = 3 ; let n = arr . length ; printMedian ( arr , n , k ) ;