Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Linked List Duplicate Elements

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Linked List Duplicate Elements. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Calsoft integration workflows may receive linked lists containing repeated identifiers from upstream processing. Given the head of a singly linked list, return every value that appears more than once, preserving the order in which each duplicate is first identified.

Formal Specification

The input is head, a reference to the first ListNode. Each node has an integer val field and a next field containing the next node or None. Return a Python list containing each duplicated value exactly once. If no value appears more than once, return an empty list.

For the examples and test cases, a linked list is represented by an array of node values. The evaluator converts that array into the corresponding ListNode chain before calling the function.

Constraints

  • 0 <= n <= 10^5
  • -10^9 <= node.val <= 10^9
  • The input is a singly linked list
  • Duplicate values must appear once in first-duplicate order

Function Signature

def find_duplicates(head):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output