CJCoding With Joseph
15free / daySign inCreate account

Common Values With Sets

Write common_values(first: list[int], second: list[int]) -> list[int] that returns a sorted list of the values that appear in both lists, each once. Put the second list into a set so each membership test is O(1), loop over the first list, and collect every value that is also in that set into another set with its add() method; return sorted() of the result, never a set itself. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: two lines, each a space-separated list of integers (possibly empty); the tests print the list your function returns.

Expected Output:

[3, 4]

= newline. The output ends with a newline — print one after the last line.

Hints3 available
Topics:
Data Structures & Algorithms
📥 Auto-Input:
1 2 3 4\n3 4 5\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.