What is the space complexity of the set solution?
Practice this question from Contains Duplicate - Set Pattern Practice Quiz, with options and an explanation.
Question
What is the space complexity of the set solution?
Option A
O(1)
Option B
O(log n)
Option C — Correct answer
O(n)
Option D
O(n^2)
Explanation
The set may store every value if all values are unique, so space is O(n).