PracticeArrays

Score Gap Sequence

BeginnerArraystraversalaccumulationstate tracking Time not estimated Not started

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

Example 1
Input: rival_changes = [3, 4, 7, 2]your_changes = [5, -2, 7, 0]
Output: [2, -6, 0, -2]
Explanation: There are four shared positions, and subtracting the rival values from your values produces [2, -6, 0, -2].
Example 2
Input: rival_changes = [4, -7]your_changes = [10, -5, 3, 8]
Output: [6, 2]
Explanation: Only the first two positions are shared, so the differences are [6, 2].
Example 3
Input: rival_changes = [6, -2, 9]your_changes = []
Output: []
Explanation: No paired position exists because your log is empty, so the result is [].

Constraints

  • 0 <= len(your_changes) <= 100
  • -1000 <= your_changes[i] <= 1000 for every i
  • 0 <= len(rival_changes) <= 100
  • -1000 <= rival_changes[i] <= 1000 for every i
  • Types: your_changes is int[], rival_changes is int[]; result is int[]

Function signature

def score_gap_sequence(your_changes: list[int], rival_changes: list[int]) -> list[int]
your_changes list[int]
Your ordered score change for each level.
rival_changes list[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.

Approved · cc006-abs_736_v414 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1