Assign beyond current length
Input
assign_and_get([1, 2], 4, 9)
Output
[1, 2, None, None, 9]
Assigning to index 4 extends the list to length 5, filling gaps with None, then places 9 at index 4.
Full lesson preview
Implement __setitem__ to support index assignment with auto-expansion behavior.
Problem statement
Task
Examples
Input
assign_and_get([1, 2], 4, 9)
Output
[1, 2, None, None, 9]
Assigning to index 4 extends the list to length 5, filling gaps with None, then places 9 at index 4.
Input format
Output format
Constraints
Samples
Input
assign_and_get(['a','b'], -1, 'z')
Output
['a', 'z']
Negative index -1 replaces the last element.