• + 0 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;
    
    }