# 710. Random Pick with Blacklist

[710. Random Pick with Blacklist](https://leetcode.com/problems/random-pick-with-blacklist/)

```python
class Solution:

    def __init__(self, n: int, blacklist: List[int]):
        self.table = {}
        self.size = n - len(blacklist)
        for num in blacklist:
            self.table[num] = num
        last = n - 1
        for num in blacklist:
            if num >= self.size:
                continue
            while last in self.table:
                last -= 1
            self.table[num] = last
            last -= 1

    def pick(self) -> int:
        idx = random.randint(0, self.size - 1)
        if idx in self.table:
            return self.table[idx]
        return idx


# Your Solution object will be instantiated and called as such:
# obj = Solution(n, blacklist)
# param_1 = obj.pick()
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://garylai.gitbook.io/algorithm-and-data-structure/problems/object-oriented-design/random-pick-with-blacklist.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
