Merge Two Sorted Leaderboards

Hard ⏱ 18 min 24% acceptance ★★★★☆ 4.2
Two game leaderboards, board_a and board_b, each contain scores already sorted in descending order. Write merge_leaderboards(board_a, board_b) that merges them into a single descending-sorted list without simply concatenating and re-sorting — use a two-pointer merge like in merge sort.

Examples

Example 1
Input
board_a = [90, 70, 50], board_b = [85, 60, 40, 10]
Output
[90, 85, 70, 60, 50, 40, 10]
Explanation

Merge by always taking the larger of the two current front elements.

Constraints

  • Both inputs are individually sorted descending.
  • 0 <= len(board_a), len(board_b) <= 10^5

Topics

ListsTwo Pointers

Companies

AmazonZomatoSwiggy

Hints

Hint 1

Keep two index pointers, one per list, and repeatedly append the larger current element.

Hint 2

When one list runs out, extend the result with the remainder of the other.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.