As reported: Pure Storage, round 2 coding (2026): implement an unordered set whose element values are
0ton − 1, wherenis the size of the set. Any language; the statement is complete as given.
Implement IntSet(n), a set that can hold integers in the range 0 … n − 1:
add(x)— insertx; returntrueif it was not already present.remove(x)— deletex; returntrueif it was present.contains(x)— return whetherxis in the set.size()— the number of elements.
Every operation should run in O(1) time.
Example
["IntSet","add","add","add","contains","remove","contains","size"]
[[5],[3],[1],[3],[1],[3],[3],[]]
-> [null,true,true,false,true,true,false,1]
Clarifications
0 ≤ x < nfor every call.- The return values of
add/removefollow the convention of LeetCode's set-design problems.
Constraints: 1 ≤ n ≤ 10^5; up to 10^5 operations.
Code runner format: two lines, LeetCode's format: the list of operations (starting with "IntSet" and its n), then the list of their argument lists. Implement the class IntSet with add, remove, contains and size; the harness prints the list of return values (null for methods that return nothing). Go: Constructor, Add, Remove, Contains, Size.