✅✅Easy to Understand || Cpp Solution || Beats 100% with 8ms of runtime 🔥🔥
Approach

Calculate Valid Range: The total number of valid integers is m = n - len(blacklist). This is because we exclude all blacklisted integers from the tota


# Approach
1. Calculate Valid Range: The total number of valid integers is m = n - len(blacklist). This is because we exclude all blacklisted integers from the total count.

2. Partition the Range: Divide the range [0, n-1] into two parts:

    (i) The first part [0, m-1] which includes some valid integers and some blacklisted integers.

   (ii) The second part [m, n-1] which includes the remaining integers.

3. Mapping Blacklisted Integers: For each blacklisted integer in the first part, find a corresponding valid integer in the second part. This mapping ensures that every number in the range [0, m-1] can be translated to a valid integer either directly (if it's valid) or via the mapped value (if it's blacklisted).



# Code
```cpp []
class Solution {
private:
    int m;
    unordered_map<int, int> mapping;
    unordered_set<int> black_set;

public:
    Solution(int n, vector<int>& blacklist) {
        m = n - blacklist.size();
        black_set = unordered_set<int>(blacklist.begin(), blacklist.end());
        vector<int> first_part_black;
        for (int num : blacklist) {
            if (num < m) {
                first_part_black.push_back(num);
            }
        }
        int candidate = m;
        for (int b : first_part_black) {
            while (black_set.count(candidate)) {
                ++candidate;
            }
            mapping[b] = candidate;
            ++candidate;
        }
    }
    
    int pick() {
        int r = rand() % m;
        if (mapping.find(r) != mapping.end()) {
            return mapping[r];
        }
        return r;
    }
};

/**
 * Your Solution object will be instantiated and called as such:
 * Solution* obj = new Solution(n, blacklist);
 * int param_1 = obj->pick();
 */
```
['C++']