You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classSolution:
def__init__(self, N: int, blacklist: List[int]):
b=set(blacklist)
self.valid_num=N-len(b) # actual valid numbers is N - |B|self.remap= {} # we need to map numbers to [N - |B|, N] which in blacklist & less than N - |B|need_map= []
forxinb:
ifx<self.valid_num:
need_map.append(x) # numbers need to be mappedj=0foriinrange(self.valid_num, N):
ifinotinb: # numbers can be returnedself.remap[need_map[j]] =ij+=1defpick(self) ->int:
idx=random.randint(0, self.valid_num-1)
returnself.remap[idx] ifidxinself.remapelseidx# Your Solution object will be instantiated and called as such:# obj = Solution(N, blacklist)# param_1 = obj.pick()