currentNode
to head
, frontNode
to None
, and endNode
to None
.currentNode
, keeping a count of the nodes traversed in listLength
.listLength
equals k
, set frontNode
to currentNode
and also start endNode
from head
.currentNode
and start moving endNode
one step at a time.currentNode
reaches the end of the list, endNode
will be at the kth node from the end.frontNode
and endNode
.head
of the modified list.