Spotting Synchronized Tokens
Context
A document review tool compares three versions of a note: an editor draft, a reviewer copy, and the published text. The versions may stop at different points. The tool needs to measure how many shared token positions contain exactly the same word in all three versions.
Problem
Write a function that counts aligned positions where the three supplied token lists contain identical words. Begin at position zero and inspect only positions that exist in every list. Add one for each position whose three words match exactly. Treat repeated words at different positions as separate matches. Stop when the shortest list ends, and return the count. Do not count distinct words globally, compare unaligned words, or inspect beyond the shared portion.
Examples
draft = ["the", "quick", "brown", "fox"]published = ["the", "quick", "brown", "dog"]review = ["the", "quick", "red", "fox"]2draft = ["go", "go", "stop"]published = ["go", "go", "stop"]review = ["go", "wait", "stop"]2draft = ["alpha", "beta"]published = ["alpha", "beta", "gamma"]review = ["alpha"]1Constraints
0 <= len(draft) <= 1001 <= len(draft[i]) <= 12 for every idraft[i]: alphabet lowercase0 <= len(review) <= 1001 <= len(review[i]) <= 12 for every ireview[i]: alphabet lowercase0 <= len(published) <= 1001 <= len(published[i]) <= 12 for every ipublished[i]: alphabet lowercasedraft, review, and published tokens contain only lowercase letters.- Types:
draftis str[],reviewis str[],publishedis str[]; result is int
Function signature
def count_shared_token_positions(draft: list[str], review: list[str], published: list[str]) -> int
draftlist[str]- The editor's token sequence.
reviewlist[str]- The reviewer's token sequence.
publishedlist[str]- The published token sequence.
- returns int
- The number of positions in the shared range where all three token lists contain the same word.
Adapted from MBPP problem task_142 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Notes
- An empty token list is valid; then the shared range has no positions.
- A word repeated at multiple positions is evaluated independently at each position.