logo
Interview
    Interview Guide
    Coding Problems List
Sponsored: Coursera
Problems

Swap Two Nodes in Linked List

Problem

Given a linked list and two values v1 and v2. Swap the two nodes in the linked list with values v1 and v2. It's guaranteed there is no duplicate values in the linked list. If v1 or v2 does not exist in the given linked list, do nothing.

Notice: You should swap the two nodes with values v1 and v2. Do not directly swap the values of the two nodes.

Example

Given 1->2->3->4->null and v1 = 2, v2 = 4. Return 1->4->3->2->null.

Online Judge