First Winning Token Pair
Context
In the game Starforge, the board records short event messages as players make moves. A bonus rule activates when one event contains two qualifying word tokens. The qualifying tokens must both start with the same badge prefix, and the first event in board order wins. Report the two tokens that activate the rule.
Problem
Implement a function that scans the event messages from left to right. In each message, identify tokens as maximal consecutive runs of lowercase English letters; every other character is a separator. Find the first message containing two token occurrences, in left-to-right order, that both begin with the supplied prefix. Return those two token strings in their original order. Repeated text is allowed, and the same token value may be returned twice when it appears in two separate occurrences. Stop considering later messages as soon as the first valid pair is found. If no message contains two qualifying tokens, return an empty list.
Examples
events = ["alpha beta gamma"]prefix = "a"[]events = ["red-blue signal", "start stone star"]prefix = "st"["start", "stone"]events = ["quiet river", "one bright moon"]prefix = "z"[]Constraints
0 <= len(events) <= 1000 <= len(events[i]) <= 200 for every i1 <= len(prefix) <= 20prefix: alphabet lowercaseA token is a maximal run of lowercase English letters.Any character other than a lowercase English letter separates neighboring tokensevent messages may be empty.- Types:
eventsis str[],prefixis str; result is str[]
Function signature
def first_winning_token_pair(events: list[str], prefix: str) -> list[str]
eventslist[str]- Board event messages scanned from earliest to latest.
prefixstr- The lowercase prefix that each qualifying token must start with.
- returns list[str]
- The first qualifying pair of token occurrences in scan order, or an empty list when no event contains two such tokens.
Adapted from MBPP problem task_305 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Notes
- Token occurrences count separately, so duplicate qualifying words can form the pair.
- The pair must come from one event, and events are prioritized by their input order.