You’re given the pointer to the head node of a linked list and an integer to add to the list. Create a new node with the given integer, insert this node at the head of the linked list and return the new head node. The head pointer given may be null meaning that the initial list is empty.

Input Format

You have to complete the SinglyLinkedListNode Insert(SinglyLinkedListNode head, int data) method which takes two arguments — the head of the linked list and the integer to insert. You should NOT read any input from stdin/console.

The input is handled by code in the editor and is as follows:

The first line contains an n integer, denoting the number of elements to be inserted at the head of the list.

The next n lines contain an integer each, denoting the element to be inserted.

#problem-solving #python #data-structures #hackerrank #linked-lists

Insert a Node at the Head of a Linked List. HackerRank Exercise
2.45 GEEK