PracticeArrays

Token Remainder Report

BeginnerArraystraversalaccumulationindex arithmetic Time not estimated Not started

Context

A document auditor records two ordered measurements for a text: the number of tokens in successive sections and a divisor assigned to each section. Create a compact report by combining corresponding measurements. The report must preserve document order and include only positions present in both lists.

Problem

Implement a function that examines the two input lists position by position. For every position available in both lists, calculate the remainder of the token measurement divided by its corresponding divisor and append it to the result. Stop as soon as either list has no value at the current position. If a divisor is zero, append 0 for that position instead of attempting division. Return the remainders in their original positional order.

Examples

Example 1
Input: divisors = [10, 7, 100]token_counts = [125, 48, 302]
Output: [5, 6, 2]
Explanation: In example 1, the executed function returns [5, 6, 2] for the three corresponding pairs.
Example 2
Input: divisors = [4, 0, 10]token_counts = [19, 0, 87, 64]
Output: [3, 0, 7]
Explanation: In example 2, the executed function returns [3, 0, 7]; the zero divisor contributes 0, and processing stops after the three positions shared by both lists.
Example 3
Input: divisors = [8, 5]token_counts = [6, 14]
Output: [6, 4]
Explanation: In example 3, the executed function returns [6, 4] for the two corresponding pairs.

Constraints

  • 0 <= len(token_counts) <= 100
  • 0 <= token_counts[i] <= 1000000 for every i
  • 0 <= len(divisors) <= 100
  • 0 <= divisors[i] <= 1000000 for every i
  • Types: token_counts is int[], divisors is int[]; result is int[]

Function signature

def build_token_remainder_report(token_counts: list[int], divisors: list[int]) -> list[int]
token_counts list[int]
Ordered token measurements for successive document sections.
divisors list[int]
Ordered divisor values paired with the document sections.
returns list[int]
The positional remainders for every pair available in both input lists; a zero divisor contributes 0.

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

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