Token Remainder Report
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
divisors = [10, 7, 100]token_counts = [125, 48, 302][5, 6, 2]divisors = [4, 0, 10]token_counts = [19, 0, 87, 64][3, 0, 7]divisors = [8, 5]token_counts = [6, 14][6, 4]Constraints
0 <= len(token_counts) <= 1000 <= token_counts[i] <= 1000000 for every i0 <= len(divisors) <= 1000 <= divisors[i] <= 1000000 for every i- Types:
token_countsis int[],divisorsis int[]; result is int[]
Function signature
def build_token_remainder_report(token_counts: list[int], divisors: list[int]) -> list[int]
token_countslist[int]- Ordered token measurements for successive document sections.
divisorslist[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.