Pad or truncate row

Write codeEasy11 min

Your task

A report generator needs every data row to have exactly size columns. Given a row of integers, a required size (size >= 0), and a fill value, return the row adjusted to that exact length: if it is too short, append the fill value until it fits; if it is too long, keep only the first size entries; if it already fits, return it unchanged. Example: [1, 2] with size 4 and fill 0 becomes [1, 2, 0, 0].

Examples

fit_to_length(row: list[int], size: int, fill: int) -> list[int]
Example 1
Inputfit_to_length([1, 2], 4, 0)
Output[1, 2, 0, 0]