PracticeArrays

Match the Score Moments

BeginnerArraystraversalaccumulationcomparison Time not estimated Not started

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

Example 1
Input: first_run = [10, 20, 30, 40]second_run = [10, 25, 30, 45]
Output: 2
Explanation: The first and third shared positions contain equal values, so the executed function returns 2.
Example 2
Input: first_run = [5, 5, 8, 12, 5]second_run = [5, 5, 9]
Output: 2
Explanation: The first two shared positions contain equal values, so the executed function returns 2.
Example 3
Input: first_run = [1, 3, 7]second_run = [2, 4, 6]
Output: 0
Explanation: No compared position contains equal values, so the executed function returns 0.

Constraints

  • 0 <= len(first_run) <= 100000
  • 0 <= first_run[i] <= 1000000 for every i
  • 0 <= len(second_run) <= 100000
  • 0 <= second_run[i] <= 1000000 for every i
  • Types: first_run is int[], second_run is int[]; result is int

Function signature

def count_matching_score_moments(first_run: list[int], second_run: list[int]) -> int
first_run list[int]
The score recorded after each move in the first player's run.
second_run list[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.
Approved · cc005r1-abs_123_v314 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1