Get Node Value [HackerRank] solution-1 | Data Structure | LinkedList | Interview

preview_player
Показать описание
This video is about HackerRank Get Node Value problem.

Problem description:
You’re given the pointer to the head node of a linked list and a specific position. Counting backwards from the tail node of the linked list, get the value of the node at the given position. A position of 0 corresponds to the tail, 1 corresponds to the node before the tail and so on.

Problem:

Linear Linked List in detail

For 1 : 1 Tutoring
WhatsApp contact : 7278222619

Follow me on:
Whatsapp:

Follow us on:
Whatsapp:

Facebook:

Linkedin:

Instagram:

#HackerRank #DataStructure #LinkedList
Рекомендации по теме
Комментарии
Автор

Hey Programmer, if you have any alternative solution feel free to post in comment section.

codingcart
Автор

explanation is too simple and good thanks a lot !!

sahilbisht
Автор

One more approach to solving this:

def getNode(head, pos):
# Write your code here
cnt = 0
temp = head
while temp != None:
temp = temp.next
cnt += 1

cnt = cnt - 1
while cnt != pos:
head = head.next
cnt -= 1


return head.data

anonymousstranger
Автор

Thanks a lot for this :) However if we just replace the first iteration to 'while ptr.next is not None', we don't have to use that 'count = count-1' before the second iteration :)

neptune
visit shbcf.ru