Parse CSV-like rows and update the first occurrence of a given ID.
You are given a list of strings, each representing a CSV row with columns: id,name,score. The id is a positive integer, name is a string (no commas), and score is a positive integer. Write a function `update_row_by_id(rows, target_id, new_score)` that processes the rows and returns a new list of strings with the same format `id,name,score`. If exactly one row has the id equal to `target_id`, replace its score with `new_score`. If no row matches or more than one row matches, return the original list unchanged. You must not modify the input list.
Function signature: `def update_row_by_id(rows: list[str], target_id: int, new_score: int) -> list[str]`
Constraints
- 0 <= len(rows) <= 1000
- Each row is a valid CSV string with exactly three fields: id (positive int), name (non-empty string without commas), score (positive int).
- target_id is a positive int.
- new_score is a positive int.
- Complexity not strict, but aim for O(n) time and O(n) memory.
Example
>>> update_row_by_id(["1,Alice,90", "2,Bob,85"], 2, 95)
['1,Alice,90', '2,Bob,95']
>>> update_row_by_id(["1,Alice,90", "2,Bob,85"], 3, 95)
['1,Alice,90', '2,Bob,85']
>>> update_row_by_id([], 1, 100)
[]
8 points
~12 min