Insert and remove
Input
insert_and_remove([1, 2, 4], 2, 3, 4)
Output
[1, 2, 3]
Insert 3 at index 2 -> [1, 2, 3, 4], then remove the first 4 -> [1, 2, 3].
Full lesson preview
Practice inserting an element at a specific position and removing the first occurrence of another element.
Problem statement
Task
Examples
Input
insert_and_remove([1, 2, 4], 2, 3, 4)
Output
[1, 2, 3]
Insert 3 at index 2 -> [1, 2, 3, 4], then remove the first 4 -> [1, 2, 3].
Input format
Output format
Constraints
Samples
Input
insert_and_remove([], 0, 'a', 'b')
Output
['a']
Inserting 'a' into an empty list then attempting to remove 'b' (not present) yields ['a'].