You are viewing a single comment's thread. Return to all comments →
Javascript Solution using Recursion. Time complexity O(N). No Arrays
function getNode(llist, positionFromTail) { let counter = 0; let flag = false; let res = null; function recur(llist,positionFromTail,flag){ if(llist && !flag){ recur(llist.next,positionFromTail,flag) counter += 1; if(counter == positionFromTail+1) { res = llist.data; flag = true; } } } recur(llist,positionFromTail) return res; }
Get Node Value
You are viewing a single comment's thread. Return to all comments →
Javascript Solution using Recursion. Time complexity O(N). No Arrays