You are given an array nums of length n representing a deck of distinct cards.
You do not have access to a built-in shuffle function, but you are given the following API:
Implement a function shuffle(nums) that randomly permutes the array in place such that every one of the n! permutations is equally likely.
rand_int(l, r)
as your source of randomness.
O(n)
time and
O(1)
extra space.
rand_int
itself is perfectly uniform and independent between calls.
Describe your algorithm, argue why the resulting permutation is uniform, and give the time and space complexity.