Reverse between equal-value nodes in list
MetaSoftware Engineer · Technical ScreenLast updated
This question evaluates a candidate's ability to manipulate singly linked lists, perform in-place sublist reversal, and manage pointer references and node boundaries.
Given the head of a singly linked list and a target value v, locate the first two nodes whose values equal v (call them A and B, with A before B) and reverse the sublist strictly between A and B in place. If fewer than two nodes with value v exist, leave the list unchanged. Aim for one pass if possible and O(
- extra space. Clarify edge cases such as adjacent equal-value nodes, multiple occurrences of v (which pair to use), and preservation of A and B positions.
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.