LinkedIn interview question

Data Mining: given a function that returns a 0 with probability p and 1 with probability (1-p), create a function that returns 1 and 0 with 0.5 probability each. DS/A: Given two sorted lists, create functions that would perform a set union and set intersections on the lists

Interview Answer

Anonymous

5 Mar 2020

import numpy as np # Given def randBinomialP(p): return np.random.binomial(1,p,1) # new func def equalProb(p): a = randBinomialP(p) b = randBinomialP(p) if a == 1 and b == 0 : return 1 elif a == 0 and b == 1 : return 0 else : return equalProb(p) #wrapper print(sum([randBinomialP(0.3) for i in range(10000)])) print(sum([equalProb(0.3) for i in range(10000)]))

1