PracticeArrays

Link the Combo Scores

BeginnerArraystraversalaccumulationstate tracking Time not estimated Not started

Context

In the arcade game Neon Rally, a player’s move scores are recorded in order. The combo board links each move with the move immediately after it. For every such neighboring pair, create one combo score by adding the two scores. Linked pairs overlap: a move may contribute to the pair before it and the pair after it.

Problem

Implement a function that receives the ordered scores from a game run. Return a new array containing the sum of each score and the score immediately following it, in the same left-to-right order. Process every complete neighboring pair exactly once. If the input has zero or one score, return an empty array because no complete pair exists. Do not remove or merge repeated scores; positions determine the pairs.

Examples

Example 1
Input: scores = [10, 25, 15, 30]
Output: [35, 40, 45]
Explanation: For [10, 25, 15, 30], the executed output is [35, 40, 45], corresponding to the consecutive sums 10+25, 25+15, and 15+30.
Example 2
Input: scores = [7, 7, 12, 7]
Output: [14, 19, 19]
Explanation: For [7, 7, 12, 7], the executed output is [14, 19, 19], corresponding to 7+7, 7+12, and 12+7; repeated scores remain in their positions.
Example 3
Input: scores = [42]
Output: []
Explanation: For [42], the executed output is [] because the input has no complete neighboring pair.

Constraints

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

Function signature

def combine_adjacent_scores(scores: list[int]) -> list[int]
scores list[int]
The scores of moves, listed in the order they occurred.
returns list[int]
An array whose elements are the sums of consecutive scores, ordered by the first score in each pair.

Adapted from MBPP problem task_206 (CC BY 4.0). Rewritten, extended and verified by Iksha.

Notes

  • Pairs are based on positions, so duplicate scores remain separate occurrences.
Approved · c008-abs_660_v414 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1