• + 0 comments

    simple recursive solution in linear time

        static int count = 0;
        static int val = 0;
        public static int getNode(SinglyLinkedListNode llist, int positionFromTail) {
        if(llist==null){
            count=0;
            return 0;
        }
        getNode(llist.next, positionFromTail);
        if(positionFromTail==count){
            val=llist.data;
        }
        count++;
        return val;
        }