Length not calculated confusion

As it’s mentioned we have to not calculate length since the size variable is given already can we use it and simply loop and get the kth element?

hi Sahil
you can do that use that size and simply print the (len – n + 1)th node from the begining of the Linked List. This can be done
But you can also find kth element without using length by:-

  1. Maintain two pointers – reference pointer and main pointer.
  2. Initialize both reference and main pointers to head.
  3. First move reference pointer to n nodes from head.
  4. Now move both pointers one by one until reference pointer reaches end.
  5. Now main pointer will point to nth node from the end.
  6. Return main pointer.