[Approach] Two Pointers + Pointer Manipulation on Linked List - O(n) Time and O(1) Space
The idea is to first count the total length of the linked list, then locate the k-th node from the beginning and the k-th node from the end using two separate traversals. Once both nodes (and their previous nodes) are found, we adjust the links of their previous nodes and swap their next pointers.
Additional if the k-th node from the beginning is the head, then after the swap the head should be updated to point to the k-th node from the end. Similarly, if the k-th node from the end is the tail, then after the swap the tail should be updated to point to the k-th node from the beginning.