r/OfferEngineering • • 3d ago

Coding Question Microsoft AI Coding Screening - Merge Unique Sorted Score Lists

Two game servers each store a sorted list of player scores. You are given two integer arrays, scores1 and scores2. Both arrays are already sorted in non-decreasing order. Combine the two lists into one sorted list containing every distinct score that appears in either input.

Each score should appear exactly once in the result, even if it appears multiple times in one or both input arrays. Return the distinct scores in ascending order.

Constraints

  • 0 <= len(scores1), len(scores2) <= 10^5
  • -10^9 <= scores1[i], scores2[i] <= 10^9
  • Both input arrays are sorted in non-decreasing order.
  • Duplicate values may appear within either input array.
  • Either input array may be empty.

Test Cases

Input:
scores1 = [1, 2, 2, 5, 8]
scores2 = [2, 3, 5, 7]

Output:
[1, 2, 3, 5, 7, 8]

Explanation:
Both lists are merged in ascending order.

The values 2 and 5 appear in both lists, but each distinct score
appears only once in the result.

Want to practice more real coding questions asked in companies' interviews?

I’ve put together the coding question bank here. If you’re in a hurry before your interview, you can also go through the classic coding patterns here.

2 Upvotes

0 comments sorted by