PracticeArrays
Recover the Level IDs
Context
A game stores a scoring table as two synchronized arrays. Each position represents one entry: level_ids[i] identifies a level, while scores[i] stores that level's points. The table keeps its entries in play order, and level IDs are unique. A replay tool needs only the level IDs, in the same order they appear in the table.
Problem
Given the ordered arrays level_ids and scores, return a new array containing every level ID exactly once and in its original entry order. The scores are associated data and must not affect the result. If the scoring table is empty, return an empty array.
Examples
Example 1
Input:
level_ids = [42, 7, 19]scores = [900, 250, 600]Output:
[42, 7, 19]Explanation: For the first example, the executed result is [42, 7, 19], matching the input level-ID order; the scores do not appear in the result.
Example 2
Input:
level_ids = [-8, 15, 3, 27]scores = [10, 80, 45, 65]Output:
[-8, 15, 3, 27]Explanation: For the second example, the executed result is [-8, 15, 3, 27], matching the input level-ID order.
Example 3
Input:
level_ids = []scores = []Output:
[]Explanation: For the empty third example, the executed result is [], matching the requirement for no entries.
Constraints
0 <= len(level_ids) <= 100-1000000000 <= level_ids[i] <= 1000000000 for every ilevel_ids: distinct elementslen(level_ids) <= len(scores) <= len(level_ids)-1000000000 <= scores[i] <= 1000000000 for every i- Types:
level_idsis int[],scoresis int[]; result is int[]
Function signature
def extract_level_ids(level_ids: list[int], scores: list[int]) -> list[int]
level_idslist[int]- Unique level IDs in the table's entry order.
scoreslist[int]- Points associated with each level ID at the same index.
- returns list[int]
- The level IDs copied in their original order, with each source ID appearing exactly once.
Adapted from MBPP problem task_833 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Notes
- The two arrays describe one ordered collection of entries by matching indices.
- An empty collection is valid.
Code
Saved