This reduces the algorithm's time complexity to O(n), compared to O(n2) for the naive implementation.
Ok I cannot understand how is it that we have n2 for the original algorithm.
You see, our first trip is to write out the random numbers. So that's 1N. and then the second step is to write out the elements based on the N. so that's 2N total?
Or is it like something to do with the second step takes longer so it's more N ?