Given 2 list, substitute one list as prefix elements of other.
Input: test_list1 = [4, 6, 8, 7], test_list2 = [2, 7, 9, 4, 2, 8]
Output : [4, 6, 8, 7, 2, 8]
Explanation: 4, 6, 8, 7 from list 1 and rest, 2 and 8 from list 2, substituting prefix of list 2.
Input: test_list1 = [4, 6], test_list2 = [2, 7, 9, 4, 2, 8]
Output : [4, 6, 9, 4, 2, 8]
Explanation: 4, 6 from list 1 and rest, 9, 4, 2 and 8 from list 2, substituting prefix of list 2.
In this, we add the list 1 and then part of list 2 after size of list 1, using len() and list slicing.
OutputThe original list 1 : [4, 6, 8, 7]
The original list 2 : [2, 7, 9, 4, 2, 8, 6, 4, 1, 10]
The joined list : [4, 6, 8, 7, 2, 8, 6, 4, 1, 10]
In this, we use * operator to perform task of packing and unpacking it to new list.
OutputThe original list 1 : [4, 6, 8, 7]
The original list 2 : [2, 7, 9, 4, 2, 8, 6, 4, 1, 10]
The joined list : [4, 6, 8, 7, 2, 8, 6, 4, 1, 10]
OutputThe original list 1 : [4, 6, 8, 7]
The original list 2 : [2, 7, 9, 4, 2, 8, 6, 4, 1, 10]
The joined list : [4, 6, 8, 7, 2, 8, 6, 4, 1, 10]
OutputThe original list 1 : [4, 6, 8, 7]
The original list 2 : [2, 7, 9, 4, 2, 8, 6, 4, 1, 10]
The joined list : [4, 6, 8, 7, 2, 8, 6, 4, 1, 10]
Time complexity: O(n), where n is the length of the second list.
Auxiliary space: O(n), since we're creating a new list to store the result.