Shuffle an Array

  • 1

    Click here to see the full article post

  • 0

    For the first num and the last num in the array, do they have the same "chance" to be switched?

  • 0

    @MindGeek I'm not super sure that I understand your question. However, if you can convince yourself that the brute force analysis is correct, it might help to think about how Fisher-Yates is actually almost identical to it. Essentially, after the ith iteration of the swapping loop, array[:i] (inclusive) is the result (so far) of the algorithm, while array[i+1:] is the "hat", or aux from the brute force solution.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.