Linked List Components
Medium · Linked Lists · about 15 minutes
Asked at Google, Amazon, Microsoft.
The linked list holds unique values. Given an array nums that is a subset of those values, return the number of connected components: maximal runs of consecutive list nodes whose values are all in nums.