PY-25

Decode and Check Token IDs

  • Easy–Medium
  • Token Sequences
  • Python

Task

Write decode_token_ids(ids, id_to_token). ids is a list of integer token IDs, and id_to_token maps valid IDs to token strings.

Return (tokens, invalid). The tokens list must have one item for every input ID. A valid ID becomes its mapped token string. An ID that is absent from the mapping becomes None, and (position, id) is appended to invalid. Positions are zero-based and invalid evidence stays in the input order.

The input list and mapping must not be changed.

Example

The invalid ID keeps a None slot, so output positions stay aligned with the input sequence.

Your implementation

Edit solution.py and keep this function name and signature:

Return exactly a two-item tuple containing the aligned token list and the list of (position, id) invalid records. Do not print, ask for input, or mutate either argument.