//Wrong solution

```
class RandomizedSet {
private:
unordered_set<int> dict;
public:
/** Initialize your data structure here. */
RandomizedSet() {}
/** Inserts a value to the set. Returns true if the set did not already contain the specified element. */
bool insert(int val) {
if(dict.find(val) != dict.end()) return false;
else{
dict.insert(val);
}
return true;
}
/** Removes a value from the set. Returns true if the set contained the specified element. */
bool remove(int val) {
if(dict.find(val) == dict.end()) return false;
else{
dict.erase(val);
}
return true;
}
/** Get a random element from the set. */
int getRandom() {
int n = rand() % (int)dict.size();
auto it = dict.begin();
for(int i = 0; i < n; i++){
it++;
}
return *it;
}
};
```

//Correct solution

```
class RandomizedSet {
private:
vector<int> nums;
unordered_map<int, int> dict;
public:
/** Initialize your data structure here. */
RandomizedSet() {}
/** Inserts a value to the set. Returns true if the set did not already contain the specified element. */
bool insert(int val) {
if(dict.find(val) != dict.end()) return false;
else{
dict[val] = nums.size();
nums.push_back(val);
}
return true;
}
/** Removes a value from the set. Returns true if the set contained the specified element. */
bool remove(int val) {
if(dict.find(val) == dict.end()) return false;
else{
int last = nums.back();
int idx = dict[val];
nums[idx] = last;
nums.pop_back();
dict[last] = idx;
dict.erase(val);
}
return true;
}
/** Get a random element from the set. */
int getRandom() {
return nums[rand() % (int)nums.size()];
}
};
```