June 4th, 2017
Today’s coding challenge was “Reverse Nodes in k-Group”
According to the site,
“Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.”
This I thought was similar to the previous problem of removing nth node. Because it is reflected on the last node of each kth node, when we get to kth node, we have a pointer at the beginning of the “length k cycle” and keep adding it as a next of the reflected node. Then the next in the cycle will be added as a next of the reflected node and thus can see reversed k list. After that, we can go to the next length k cycle by calling the function again with the reflected node’s next pointer. We can take care of not having full length k by the fast pointer which will signal that full length k does not exist by having a null pointer before length k is filled up.