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.
rslt,counter=0,-1defgetNode(llist,positionFromTail,x=0):globalrslt,counter#Recursion to start at the end of the list (var x equals n at the nth node):x+=1ifllist.next!=None:getNode(llist.next,positionFromTail,x)#This part is executed once we reach the final node and then for each previous one (counter equals 0 at end and +=1 at each previous node): counter+=1ifpositionFromTail==counter:rslt=llist.data#Here we reset the global counter once we reach the head of the list:ifx==1:counter=-1returnrslt
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Get Node Value
You are viewing a single comment's thread. Return to all comments →
My Python solution with recursion: