Dsa
Linked List
Hard
Rotate Linked List
You are given a linked list and a number k. Your task is to rotate the linked list to the right by k places. For example, if you have the linked list '1 -> 2 -> 3 -> 4 -> 5' and k = 2, you should return '4 -> 5 -> 1 -> 2 -> 3'. If k is greater than the length of the linked list, it should work correctly as well.
Input format:
A single line of space-separated integers representing the linked list followed by an integer k.
Output format:
A single line of space-separated integers representing the rotated linked list.
Example:
Input:
1 2 3 4 5 2
Output:
4 5 1 2 3
Key concepts
linked_listrotation
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now