Amazon interview question

Linked list problem from leetcode