We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The problem here is you add a new node to the linked list but never update the head or the tail when needed.
For example when the passed head is null (empty list). You just return the newNode. The head supposes to reference to the newNode but you never do it here. You cannot do it because you do not have access to the head here.
If you inserted at the last position of a not empty linked list, then you would update the tail as well but you cannot do it. You do not have access to the tail.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Insert a node at a specific position in a linked list
You are viewing a single comment's thread. Return to all comments →
The problem here is you add a new node to the linked list but never update the head or the tail when needed. For example when the passed head is null (empty list). You just return the newNode. The head supposes to reference to the newNode but you never do it here. You cannot do it because you do not have access to the head here. If you inserted at the last position of a not empty linked list, then you would update the tail as well but you cannot do it. You do not have access to the tail.