Python solution using hashmap
\nfrom random import randint\nclass Solution:\n\n    def __init__(self, n: int, blacklist: List[int]):\n        self.n = n\n        self.hm = {}\n        blackl
```\nfrom random import randint\nclass Solution:\n\n    def __init__(self, n: int, blacklist: List[int]):\n        self.n = n\n        self.hm = {}\n        blacklist.sort()\n        self.blacklist = set(blacklist)\n        blacklistIndex = 0\n        for i in range(n-len(blacklist), n):\n            if i not in self.blacklist:\n                self.hm[blacklist[blacklistIndex]] = i\n                blacklistIndex+= 1\n            \n        # validIndex = n-1\n        # for i in range(len(blacklist)):\n        #     while validIndex >= 0:\n        #         if validIndex not in self.blacklist: break\n        #         validIndex -= 1\n        #     if blacklist[i] >= validIndex: break\n        #     self.hm[blacklist[i]] = validIndex\n        #     self.blacklist.remove(blacklist[i])\n        #     validIndex -=1\n        # self.validIndex = validIndex\n\n    def pick(self) -> int:\n        randomNum = randint(0,self.n-len(self.blacklist)-1)\n        # randomNum = randint(0,max(0,self.validIndex))\n        if randomNum not in self.hm: return randomNum\n        return self.hm[randomNum]\n        \n\n```
[]