← 返回 meta 的题目列表Random Without Replacement (Fisher–Yates Shuffle)
类型:online_judge
Problem: Random Without Replacement (Fisher–Yates Shuffle)
Given an integer n, representing n items labeled 0..n-1, generate a uniformly random permutation in which every item appears exactly once (i.e., random without replacement).
Requirements:
Must run in O(n) time.
Extra space should be O(1) if possible (excluding the output array itself).
You may call a standard RNG function randint(l, r) that returns a uniform random integer in the inclusive range [l, r].
Input
One integer n.
Output
Print n integers: the generated random permutation.
Constraints
1 <= n <= 2 * 10^5
Notes
The interviewer cares primarily about uniformity and O(n) complexity, not any specific output.
Example
Input
1
Output
0