Bloomberg LP Interview Question
Software Engineer / DevelopersGiven an array of 1 to n.
Choose random number between indices 0 and n-1. Return that element. Replace element with rightmost element in array.
Now choose random number between indices 0 and n-2.
Repeat above m times.
@metta I am not sure of this but i think your algorithm may not work, since you are restricting each element to be selected only once. In a randomly selected m elements, there is a probability for element to repeat. But in your algorithm, elements do not repeat at all.
kunths shuffle
- Anonymous November 09, 2010