Tap here to switch tabs
Problem
Submissions

Problem: Linked List Components

Linked List Components asks you to count maximal consecutive runs in a singly linked list whose node values all appear in a given subset array.

Statement

You are given the head of a singly linked list containing nn nodes with unique values and an integer array nums containing a subset of the values present in the linked list.

A connected component is defined as a maximal sequence of linked list nodes appearing consecutively such that every node in the sequence has its value present in nums.

Return the total number of connected components formed by the elements of nums.

Constraints:

  • The number of nodes in the linked list is nn.

  • 1≤n≤1041 \leq n \leq 10^4

  • 0≤0 \leq Node.val <n< n

  • All the values of Node.val are unique.

  • 1≤1 \leq nums.length ≤n\leq n

  • 0≤0 \leq nums[i] <n< n

  • All the values of nums are unique.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Linked List Components

Linked List Components asks you to count maximal consecutive runs in a singly linked list whose node values all appear in a given subset array.

Statement

You are given the head of a singly linked list containing nn nodes with unique values and an integer array nums containing a subset of the values present in the linked list.

A connected component is defined as a maximal sequence of linked list nodes appearing consecutively such that every node in the sequence has its value present in nums.

Return the total number of connected components formed by the elements of nums.

Constraints:

  • The number of nodes in the linked list is nn.

  • 1≤n≤1041 \leq n \leq 10^4

  • 0≤0 \leq Node.val <n< n

  • All the values of Node.val are unique.

  • 1≤1 \leq nums.length ≤n\leq n

  • 0≤0 \leq nums[i] <n< n

  • All the values of nums are unique.