FastPrepMedian of an Array
Problems/Median of an Array

Median of an Array

Akuna Capital logoAkuna Capital● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names finding the median of an array as a live phone coding task for a Junior Quantitative Researcher - Machine Learning role. It does not give the value type, the size limits, whether the input can be empty, the rule for even lengths, or the exact function signature.

Our version is about 90% the same as the reported question.

You are given a nonempty integer array values. Its elements may be in any order and may contain duplicates. Return the median of all its values, counting every occurrence.

Let n be the array length. Consider the values in nondecreasing order, using zero-based indices:

  • If n is odd, the median is the value at index floor(n/2).
  • If n is even, the median is the arithmetic mean of the values at indices n/2 - 1 and n/2.

Return one floating-point number. Under these bounds, the median is always an integer or a half-integer.

Do not change values. Each call must use its own working state and must not depend on earlier calls.

For a returned value answer, require |answer - exact| <= 0.000000001 * max(1, |exact|), where exact is the median.

Function

arrayMedian(values: int[]) → double

Examples

Example 1

values = [3,1,4,1,5]return = 3.0

In sorted order, the values are [1,1,3,4,5]. There are 5 values, so the median is the value at index 2, which is 3.

Example 2

values = [8,2,6,4]return = 5.0

In sorted order, the values are [2,4,6,8]. The two central values are 4 and 6. Their arithmetic mean is (4 + 6)/2 = 5.

Example 3

values = [-5]return = -5.0

The only value is -5, so the median is -5.

Constraints

  • 1 <= values.length <= 60.
  • Every integer in values is between -10^6 and 10^6, inclusive.

More Akuna Capital Phone Screen questions

  • Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Biased Coin: Probability of Exactly h HeadsPHONE SCREEN · Seen Nov 2026
  • Positive Nth Root with Gradient DescentPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Two SumOA · PHONE SCREEN · Seen Sep 2026
  • Maximum Value in a Binary TreePHONE SCREEN · Seen Sep 2026
  • Tiered Expiring Item StorePHONE SCREEN · Seen Aug 2026
  • Statistics for the Latest K ValuesPHONE SCREEN · Seen Nov 2025
  • Remove Duplicates While Preserving OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025
  • Sliding Window MaximumPHONE SCREEN · Seen Oct 2025
  • Evaluate a PolynomialPHONE SCREEN · Seen Oct 2025

Similar questions at other companies

  • Merge Overlapping IntervalsAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Merge Weekday and Time IntervalsNextdoor · PHONE SCREENNextdoor interview questions
  • Peak Chat Load Across AgentsCresta · PHONE SCREENCresta interview questions
  • 3SumAmazon · PHONE SCREEN
  • Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Longest Consecutive SequenceJP Morgan Chase · PHONE SCREENJP Morgan Chase interview questions
  • Determine the Winner of Three-Card HandsOpenAI · PHONE SCREENOpenAI interview questions
  • Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEWAgoda interview questions
  • Top K Frequent Elements with a Recency TiebreakSwiggy · PHONE SCREEN
  • Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions

Interview reports that mention this question

  • Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)

Akuna Capital interview experiences

  • Akuna Capital Quant Trader and QR Interviews: 5 Experiences
  • Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
  • Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
  • Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
  • Akuna Capital QR Coding Interviews: 17 Experiences (Part 2 of 6)
All Akuna Capital interview questionsSee Akuna Capital hiring insights
Saved
class Solution {
    public double arrayMedian(int[] values) {
        // write your code here
    }
}
Checking account…