7
$\begingroup$

this question occurred in my interview,

How to find the median values using the min, max, and sum values of the given 5 elements?

for eg if given 3 elements we can use sum - min - max

a = [3,6,9] here median is 6 min = 3 max = 9 sum = 18

18 - 9- 3 = 6 which is the same as median values.

so the question is how to find the median for the 5 elements?

find for the a = [1,2,3,4,10]

$\endgroup$

2 Answers 2

17
$\begingroup$

If you only know the min, max, and sum of the 5 numbers, you cannot determine the median. E.g.

median(1, 2, 3, 4, 5)=3
median(1, 2.1, 2.8, 4.1, 5)=2.8.

But both have (min, max, sum) = (1, 5, 15).

$\endgroup$
1
$\begingroup$

Find the max and min of the initial list. Create a new list without those 2 elements. Find the new max, min and sum and use the method you mentioned,

median = sum - min - max

$\endgroup$
3
  • $\begingroup$ Or do the "throw away min and max" step twice. $\endgroup$
    – frank
    Commented Jul 30, 2022 at 9:48
  • 11
    $\begingroup$ This assumes knowing all five numbers, hence an ability to find the median directly, not from the max, min and sum only... $\endgroup$
    – Xi'an
    Commented Jul 30, 2022 at 13:15
  • 1
    $\begingroup$ I suspect that this is the answer sought by the person originally proposing the riddle. $\endgroup$ Commented Aug 16, 2022 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.