Arena Score Median
Context
Two rival players have completed the same number of runs in a score-based game. Each player's scores are already sorted from lowest to highest. The arena wants one typical score for the combined results, using the median of all scores while avoiding unnecessary storage for a merged sequence.
Problem
Given two equally sized sorted score sequences, determine the median of all scores when the sequences are considered together as one multiset. Repeated scores must remain repeated. Traverse the two sequences from left to right by repeatedly selecting the smaller available score. Keep only the previously selected score and the latest selected score, and stop once the central positions have been reached. If the combined count is odd, return the central score. If it is even, return the arithmetic mean of the two central scores.
Examples
first_scores = [1, 4, 7]second_scores = [2, 5, 8]4.5first_scores = [-3, 0, 4, 10]second_scores = [-1, 2, 4, 9]3first_scores = [2, 2, 6, 12, 12]second_scores = [1, 2, 8, 12, 15]7Constraints
1 <= len(first_scores) <= 100000-1000000 <= first_scores[i] <= 1000000 for every ifirst_scores: non emptyfirst_scores: sorted non decreasinglen(first_scores) <= len(second_scores) <= len(first_scores)-1000000 <= second_scores[i] <= 1000000 for every isecond_scores: non emptysecond_scores: sorted non decreasing- Types:
first_scoresis int[],second_scoresis int[]; result is float
Function signature
def arena_score_median(first_scores: list[int], second_scores: list[int]) -> float
first_scoreslist[int]- The first player's scores in non-decreasing order.
second_scoreslist[int]- The second player's scores in non-decreasing order, with the same length as first_scores.
- returns float
- The median score of the combined multiset, returned as a number; it may be fractional when the combined count is even.
Adapted from MBPP problem task_622 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Notes
- Both sequences have equal length, including the smallest valid case of one score each.
- Duplicate, negative, and zero scores are valid values.