Match the Score Moments
Context
Two players complete the same game mode and record their score after each move. Their runs may contain different numbers of moves. Compare the records by move position and measure how often both players had exactly the same score at that position.
Problem
Implement a function that receives two integer score histories. Compare the values at position 0, position 1, and so on, stopping as soon as one history has no value at the current position. Add one to the result for every compared position where the two scores are equal. Each position is counted independently, so repeated scores at different positions may contribute multiple matches. Return the total number of matching positions. If there are no shared positions, return zero.
Examples
first_run = [10, 20, 30, 40]second_run = [10, 25, 30, 45]2first_run = [5, 5, 8, 12, 5]second_run = [5, 5, 9]2first_run = [1, 3, 7]second_run = [2, 4, 6]0Constraints
0 <= len(first_run) <= 1000000 <= first_run[i] <= 1000000 for every i0 <= len(second_run) <= 1000000 <= second_run[i] <= 1000000 for every i- Types:
first_runis int[],second_runis int[]; result is int
Function signature
def count_matching_score_moments(first_run: list[int], second_run: list[int]) -> int
first_runlist[int]- The score recorded after each move in the first player's run.
second_runlist[int]- The score recorded after each move in the second player's run.
- returns int
- The number of positions within the shared range where both score histories contain the same value.
Adapted from MBPP problem task_723 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Notes
- Repeated score values remain separate positional comparisons.
- The shorter history determines where comparison stops.