Maximize the median of the given array after adding K elements to the same array | Function to return the maximized median ; Sort the array ; If size is even ; If size is odd ; Driver code
function getMaxMedian ( arr , n , k ) { let size = n + k ; arr . sort ( ( a , b ) => a - b ) ; if ( size % 2 == 0 ) { let median = ( arr [ Math . floor ( size / 2 ) - 1 ] + arr [ Math . floor ( size / 2 ) ] ) / 2 ; return median ; } let median = arr [ Math . floor ( size / 2 ) ] ; return median ; } let arr = [ 3 , 2 , 3 , 4 , 2 ] ; let n = arr . length ; let k = 2 ; document . write ( getMaxMedian ( arr , n , k ) ) ;