Reverse sublist between equal-value nodes
MetaSoftware Engineer · Technical ScreenLast updated
This question evaluates linked-list manipulation and pointer-management skills, focusing on reversing an in-place sublist between two nodes with equal values while respecting O(n) time and O(1) extra space constraints.
Given the head of a singly linked list and a target value v that appears at least twice, reverse the sublist starting at the first node with value v and ending at the second node with value v (inclusive). If v appears fewer than two times, return the original list. Provide an in-place O(n) time, O(
- extra space solution and discuss edge cases (adjacent boundaries, when the sublist includes the head or tail).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.