Help Mr. Sidhu, your favourite math teacher, find the median mark on a class test. The first line will consist of
, the number of marks. This line will be followed by
lines with each containing a integer mark
. Round to the nearest integer if necessary. We use standard mathematical conventions for rounding.
Sample Input 1
2
50
100
Sample Output 1
75
Sample Input 2
3
40
99
100
Sample Output 2
99
Comments
I have an ArrayOutOfBoundsException on test case 11, and am failing test cases 7 and 10.
Is there anything I might be doing wrong?
Have you tried running your code against the samples? Specifically, your most recent submission fails the first sample case.
I tested my code out with the sample on an online compiler and it worked, but it doesn't seem to on here. Can someone take a look?
You have to sort the array in order to find the median.
Your code fails this case: 4 30 59 76 23
I'm failing test cases #7, #10 and #100. Can anyone please give me a hint?
You're not rounding.
And what's Testcase #100?
I would be interested to know why I am failing the last two test cases. Any hints?
Try reading the docs for
round
I read the past comments and tried my own test cases. What else can be wrong? I am missing 2.2 pts.
Is there anything I should watch out for in this problem?
and don't assume that the input is sorted. In your case, divide by 2.0 rather than by 2, or else the answer would be cast into an integer (rounded down for positive numbers; 1.9 => 1 instead of 2).
Thank you for your help!
Just round properly.