We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Sorting
  4. Find the Median

Find the Median

Problem
Submissions
Leaderboard
Discussions

The median of a list of numbers is essentially its middle element after sorting. The same number of elements occur after it as before. Given a list of numbers with an odd number of elements, find the median?

Example

The sorted array . The middle element and the median is .

Function Description

Complete the findMedian function in the editor below.

findMedian has the following parameter(s):

  • int arr[n]: an unsorted array of integers

Returns

  • int: the median of the array

Input Format

The first line contains the integer , the size of .
The second line contains space-separated integers

Constraints

  • is odd

Sample Input 0

7
0 1 2 4 6 5 3

Sample Output 0

3

Explanation 0

The sorted . It's middle element is at .

Author

HackerRank

Difficulty

Easy

Max Score

35

Submitted By

100970

Need Help?


View discussions
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy