Ctrl K

Values in Both Lists

Easy
You are given two integer lists left and right. Return every distinct value that occurs in both left and right. Each value must appear in the answer exactly once, no matter how often it repeats in the lists. The answer may be in any order.
Example 1
left=[3, 8, 8, 1], right=[8, 5, 3, 8] → [8, 3]

The shared values are 3 and 8. The 8 appears several times but is listed once; [8, 3] is accepted too.

Example 2
left=[0, 2], right=[4, 6, 1] → []

There are no shared values.

Constraints
  • 1 ≤ len(left), len(right) ≤ 1000
  • 0 ≤ elements ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsShared Values With Repeats EasyTwice as Much EasyPairs With a Fixed Gap MediumSpells Without Neighbors MediumThe Lost Ticket Easy
loading Python…
Input
left=[3, 8, 8, 1], right=[8, 5, 3, 8]
Expected
[8, 3]

Run checks the first 3 tests in your browser. Submit checks all 122 tests on the server, hidden ones included.