Read a Matrix Row

A matrix is often passed as plain text: rows are separated by line breaks, and numbers inside each row are separated by spaces. The function matrix_row receives matrix_string and a row index, where counting starts from 1. Find that row, convert its values to integers, and return them as a list.

Примеры

Ввод
"1 2 3\n4 5 6\n7 8 9", 1
Вывод
[1, 2, 3]
Ввод
"1 2 3\n4 5 6\n7 8 9", 2
Вывод
[4, 5, 6]
Ввод
"1 2 3\n4 5 6\n7 8 9", 3
Вывод
[7, 8, 9]

Нужно реализовать

def matrix_row(matrix_string: str, index: int) -> list[int]:

Теги

arraystrings
PostgreSQLv16

Your code output will appear here

Visible tests
1
Input
"1 2 3\n4 5 6\n7 8 9", 1
Expected[1,2,3]
2
Input
"1 2 3\n4 5 6\n7 8 9", 2
Expected[4,5,6]
3
Input
"1 2 3\n4 5 6\n7 8 9", 3
Expected[7,8,9]
4
Input
"7 8\n9 10", 2
Expected[9,10]
5
Input
"1 2 3\n4 5 6\n7 8 9", -1
Expected[4,5,6]
6
Input
"1 2 3\n4 5 6\n7 8 9", 0
Expected[7,8,9]
Focus radio
Paused · SomaFM · Fluid