Domanda di colloquio di 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.

Risposta di colloquio

Anonimo

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