Find the point on X | Function to find median of the array ; Sort the given array ; If number of elements are even ; Return the first median ; Otherwise ; Driver Code
def findLeastDist ( A , N ) : NEW_LINE INDENT A . sort ( ) ; NEW_LINE if ( N % 2 == 0 ) : NEW_LINE INDENT return A [ ( N - 1 ) // 2 ] ; NEW_LINE DEDENT else : NEW_LINE INDENT return A [ N // 2 ] ; NEW_LINE DEDENT DEDENT A = [ 4 , 1 , 5 , 10 , 2 ] ; NEW_LINE N = len ( A ) ; NEW_LINE print ( " ( " , findLeastDist ( A , N ) , " , ▁ " , 0 , " ) " ) ; NEW_LINE