FunctionRacerProblemsRace

Common Values of Two Sorted Lists

EasyLinked listsPython, JavaScript, TypeScript, Java, C++

Lists l1 and l2 are both sorted from smallest to largest. Return a new sorted list holding every value that appears in both, each value listed once even if it repeats.

Linked lists appear in the tests as the list of their values, like [1,2,3]. Each node is a ListNode with .val and .next; the class is already defined for you.

Example 1

l1 [1,2,2,3,5]
l2 [2,2,5,6]
returns [2,5]

Both contain 2 and 5.

Example 2

l1 [1,3]
l2 [2,4]
returns []

Nothing in common.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Linked lists problems