DSAMaster Logo
DSAMaster
BackeasyLinked Lists

Filter Linked List Nodes by Timestamp

Problem Description

Given the head of a singly linked list, where each node has an integer val and an integer timestamp. Implement a function filterNodes(head, targetTimestamp) that recursively traverses the linked list. The function should collect the val of all nodes whose timestamp is strictly greater than targetTimestamp. The collected vals must be returned as a list, maintaining their original order as they appear in the linked list.

Example 1
Input
head = [(10, 100), (20, 150), (30, 90), (40, 200), (50, 120)], targetTimestamp = 130
Output
[]

Explanation: Nodes with timestamps 150 and 200 are strictly greater than 130. Their values (20 and 40) are collected in order.

Example 2
Input
head = [(5, 50), (15, 60), (25, 70)], targetTimestamp = 80
Output
[]

Explanation: All node timestamps (50, 60, 70) are less than or equal to 80. No values are collected.

Constraints

  • The number of nodes in the list `N` is between `0` and `10^4`.
  • `0 <= Node.val <= 10^9`
  • `0 <= Node.timestamp <= 10^9`
  • `0 <= targetTimestamp <= 10^9`
  • The solution must use a recursive approach.
00:00
Loading...

Sign in to Solve

Access the full code editor, ThinkBuddy AI hints, and track your progress.

Sign in Free
Test Cases & Output
Enter test input here...
Click "Run Code" to execute