Challenges: Insert at Position and Merge Lists
Test your knowledge by solving this coding challenge.
The mergeLists
function
Problem statement
The input consists of two lists. Write a function, mergeLists
, which takes the two lists as inputs and concatenates them together. The list2
array should be appended to the end of list1
.
The list2
array must be the empty list after the merge process.
For example:
list1 = [1, 2, 3]
list2 = [4, 5, 6]
After mergeLists
:
list1 = [1, 2, 3, 4, 5, 6]
list2 = []
Challenge
Complete the function in the following code widget using local references. The definition of the list structure is present in the background.
Note: We stress again that it’s crucial to make a memory drawing to be able to solve problems with linked lists. It’s hard to figure out how to set the pointers without visualizing them on paper beforehand.
Get hands-on with 1400+ tech skills courses.