Linked List Insertion
Problem Statement
Create a link list of size N according to the given input literals. Each integer input is accompanied by an indicator which can either be 0 or 1. If it is 0, insert the integer in the beginning of the link list. If it is 1, insert the integer at the end of the link list.
Hint : When inserting at the end, make sure that you handle NULL explicitly.
Example 1
Example 2
Task
You only need to complete the functions insertAtBeginning() and insertAtEnd() that takes the head of link list and integer value of the data to be inserted as inputs and returns the head of the modified link list.
Expected Time Complexity : O(1) for insertAtBeginning() and O(N) for insertAtEnd().
Expected Auxiliary Space : O(1) for both.
Constraints :
1 <= N <= 104
0 Comments