← Back to Data Structures & Algorithms
Question 528
Duplicates With A Set
Duplicates With A Set
Write has_duplicates_set(values: list[int]) -> bool that walks the list once, keeping a set of the values already seen, and returns True the moment a value is met for the second time; return False if the loop finishes. Because a set membership test is O(1), the whole function is O(n), far better than the nested-loop version. Use the set's add() method. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: one line of space-separated integers (possibly empty); the tests print the boolean your function returns.
Expected Output:
True= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
Data Structures & AlgorithmsBig-O
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.