Pergunta de entrevista da empresa LinkedIn

Given an array of integers, write a function that will produce a random permutation of the input array.

Respostas da entrevista

Sigiloso

23 de ago. de 2017

To ensure a uniform distribution; for each index in the new array; every "unpicked" member of the old array must have an equal chance of being chosen public static void generateRandomSequence(int[] arr){ Random random = new Random(); for (int i =0;i

4

Sigiloso

19 de fev. de 2019

Use Fisher–Yates shuffle Algorithm to get uniform random array.

Sigiloso

20 de ago. de 2017

I wrote an algorithm that would pick two indices of the input array at random and swap them some number of times at least as large as the size of the input array. The interviewer argued that this would not produce a uniformly distributed permutation of the input array. I am still unsure if this is correct, but either way, I think it's a pretty nitpicky criticism of the answer.