Day 16 – Linked List Insertions, Reversal, Midpoint, Merge, Nth Deletion, and Addition
Insert Node at Head
Intuition: Create a new node, point it to the current head, and update the head.
Node* insertAtHead(Node* head, int val) {
Node* newNode = new Node(val);
newNode->next = head;
return newNode;
}
// TC: O(1)
// SC: O(1)
...