[Python] pick from list of valid ranges
\n"""\nStore array of valid ranges, then pick random range, and random\nvalue from that range.\n"""\nclass Solution:\n\n    def __init__(self, n: int, blacklist
```\n"""\nStore array of valid ranges, then pick random range, and random\nvalue from that range.\n"""\nclass Solution:\n\n    def __init__(self, n: int, blacklist: List[int]):\n        self.n = n\n        self.r = []\n\n        if not blacklist:\n            self.r.append((0, n - 1))\n            return\n\n        b = sorted(blacklist)\n        if b[0] != 0:\n            self.r.append((0, b[0] - 1))\n\n        for i in range(len(b) - 1):\n            if b[i] + 1  != b[i + 1]:\n                self.r.append((b[i] + 1, b[i + 1] - 1))\n\n        if b[-1] != n - 1:\n            self.r.append((b[-1] + 1, n - 1))\n\n    def pick(self) -> int:\n        left, right = random.choice(self.r)\n        return random.randint(left, right)\n```
['Sorting', 'Python', 'Python3']