Dsa
Linked List
Easy
Reverse a Portion of Linked List
Given the head of a linked list, and two integers left and right, reverse the linked list from position left to position right, and return the modified linked list.
Input Format:
The first line contains space-separated integers representing the linked list, followed by -1 to indicate the end.
The second line contains two space-separated integers left and right (1-indexed positions).
Output Format:
Output the modified linked list as a space-separated integer sequence followed by -1.
Example:
Input:
1 2 3 4 5 -1
2 4
Output:
1 4 3 2 5 -1
Key concepts
linked_listreversesublist
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