First Combo in the Move Code
Context
A game records a player's moves as one lowercase string. A rival wants to know where a particular combo first appears in that record. Return the requested combo together with its first start and exclusive end positions. If the combo never appears, report the combo with -1 for both positions.
Problem
Implement a function that searches the move-code string for the first literal occurrence of the requested combo. Return a three-item string list: the requested combo, its inclusive starting index, and its exclusive ending index, with both indices written as decimal strings. Search from the beginning and select the earliest occurrence. If no occurrence exists, return the requested combo followed by "-1" and "-1". Do not alter either input string.
Examples
combo = "aba"move_code = "abacabad"["aba", "0", "3"]combo = "down"move_code = "leftupdownright"["down", "6", "10"]combo = "spin"move_code = "jumpdashroll"["spin", "-1", "-1"]Constraints
1 <= len(move_code) <= 240move_code: alphabet lowercase1 <= len(combo) <= len(move_code)combo: alphabet lowercasemove_code and combo contain only lowercase letters.- Types:
move_codeis str,combois str; result is str[]
Function signature
def find_first_combo(move_code: str, combo: str) -> list[str]
move_codestr- The recorded lowercase move sequence to search.
combostr- The lowercase move pattern to find.
- returns list[str]
- A three-item list containing combo, its first-match start index as a string, and its exclusive end index as a string; use "-1" for both indices when absent.
Adapted from MBPP problem task_607 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Notes
- Indices are zero-based.
- The ending index is exclusive.
- The returned combo must remain unchanged even when no match exists.