Score Gap Sequence
Context
In the arcade game Neon Ladder, two players record score changes across successive levels. The first list contains your changes and the second contains your rival's changes. The level logs may end at different times. Calculate the score gap for every level recorded by both players, keeping the original order.
Problem
Write a function that compares two ordered score-change logs. At each shared position, subtract the rival's value from your value and append the difference to the result. Process positions from the beginning in lockstep and stop as soon as either log has no value at the current position. Return the collected score gaps. Empty logs are valid, and negative, zero, and repeated score changes must be handled with ordinary integer subtraction.
Examples
rival_changes = [3, 4, 7, 2]your_changes = [5, -2, 7, 0][2, -6, 0, -2]rival_changes = [4, -7]your_changes = [10, -5, 3, 8][6, 2]rival_changes = [6, -2, 9]your_changes = [][]Constraints
0 <= len(your_changes) <= 100-1000 <= your_changes[i] <= 1000 for every i0 <= len(rival_changes) <= 100-1000 <= rival_changes[i] <= 1000 for every i- Types:
your_changesis int[],rival_changesis int[]; result is int[]
Function signature
def score_gap_sequence(your_changes: list[int], rival_changes: list[int]) -> list[int]
your_changeslist[int]- Your ordered score change for each level.
rival_changeslist[int]- The rival's ordered score change for each level.
- returns list[int]
- A list containing your_changes[i] minus rival_changes[i] for every index available in both input lists, in order.
Adapted from MBPP problem task_282 (CC BY 4.0). Rewritten, extended and verified by Iksha.