Efficient Random Pick with Blacklist using Mapping | Accepted ✅ 100%
IntuitionPartition the range [0, n-1] into whitelist and blacklist ranges. Map blacklisted numbers in the whitelist to non-blacklisted numbers in the blacklist
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Partition the range `[0, n-1]` into whitelist and blacklist ranges. Map blacklisted numbers in the whitelist to non-blacklisted numbers in the blacklist for uniform randomness.

# Approach
<!-- Describe your approach to solving the problem. -->
1. Calculate the size of the whitelist range (`space = n - blacklist.length`).

2. Use a hash map to store mappings of blacklisted numbers in the whitelist range to non-blacklisted numbers in the blacklist range.

3. During the `pick` operation, generate a random number in the whitelist range. If the number is blacklisted, return its mapped value; otherwise, return the number itself.

# Complexity
- Time complexity:
    - Initialization: `O(m)`, where `m` is the size of the blacklist.
    - Pick: `O(1)` per call.

- Space complexity:
    - `O(m)` for storing the map and blacklist set.

# Code
```javascript []
/**
 * @param {number} n
 * @param {number[]} blacklist
 */
var Solution = function (n, blacklist) {
    this.space = n - blacklist.length; // Size of the whitelist range
    this.map = new Map();

    // Create a set of blacklisted numbers for quick lookup
    const blacklistSet = new Set(blacklist);

    // Initialize a pointer for the blacklist range
    let last = n - 1;

    // Map blacklisted numbers in the whitelist range to non-blacklisted numbers in the blacklist range
    for (const num of blacklist) {
        if (num < this.space) {
            // Find a non-blacklisted number in the blacklist range
            while (blacklistSet.has(last)) {
                last--;
            }
            // Map the blacklisted number to the non-blacklisted number
            this.map.set(num, last);
            last--;
        }
    }
};

/**
 * @return {number}
 */
Solution.prototype.pick = function () {
    const randomNum = Math.floor(Math.random() * this.space);
    // If the random number is blacklisted, return its mapped value; otherwise, return the number itself
    return this.map.has(randomNum) ? this.map.get(randomNum) : randomNum;
};

/** 
 * Your Solution object will be instantiated and called as such:
 * var obj = new Solution(n, blacklist)
 * var param_1 = obj.pick()
 */
```
['Array', 'Hash Table', 'Math', 'Binary Search', 'Sorting', 'Randomized', 'JavaScript']