This is an O(n) time, O(1) space solution. Find out list length by iterating through it. Recalculate k by mod len to reduce k to less than len. If new k is 0 return. Use slow and fast pointers to navigate fast to one before last and slow to one before new head. Rewire the pointers in these positions. So, split list after slow and join fast (last) to head. Return new head (node after slow).
-
Recent Posts
Recent Comments
Archives
Categories
Meta