Tripadvisor Interview Question

Randomly select distinct objects from a big array. What if you cannot change the order of the original array?

Interview Answer

Anonymous

Jul 6, 2012

First question is classic random selection problem, which involves manipulation of the original array (shifting chosen ones to the end of the array). Second question: maintain a list of shifted elements in another set. Basically provides an override. Then use the same algorithm.