Domanda di colloquio di Tripadvisor

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

Risposta di colloquio

Anonimo

6 lug 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.