Pergunta de entrevista da empresa Microsoft

Create a function that receives an array of integers as input, and each time it's called, it returns the same array but with the elements in a random order. Each possible scrambled array should have the same probability.

Resposta da entrevista

Sigiloso

18 de jul. de 2025

I randomized an index from 0 to n - 1, and swapped the element at array[index] with array[n - 1]. Then randomized an index from 0 to n - 2, and swapped the element at array[index] with array[n - 2], and so on...