Katkat

Reverse between equal-value nodes in list

MetaSoftware Engineer · Technical Screen

Last 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(

  1. 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.