Sign in to track progress, unlock prep layers, and browse your pipeline.Sign in
Implement an unbiased array shuffle
Problem: Implement an Unbiased Array Shuffle
Implement an in-place function shuffle(arr) that returns a uniformly random permutation of the input array. The algorithm must satisfy the following constraints:
- Unbiased: All
n!possible permutations of the array must be equally likely. - Time Complexity: Run in O(n) time.
- Space Complexity: Use O(1) extra space.
- Edge Cases: Correctly handle empty arrays or arrays containing a single element.
Candidates are expected to:
- Explain their chosen approach.
- Justify the uniformity of their algorithm at a high level.
- Analyze the time and space complexity of their solution.
AI interview prep
Core dilemma
Achieving true statistical uniformity for all permutations within strict O(N) time and O(1) space constraints, while correctly handling edge cases and justifying the probabilistic guarantees.
Mid-level signals3
Senior signals3
Red flags3
2 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Implement an unbiased array shuffle
Problem: Implement an Unbiased Array Shuffle
Implement an in-place function shuffle(arr) that returns a uniformly random permutation of the input array. The algorithm must satisfy the following constraints:
- Unbiased: All
n!possible permutations of the array must be equally likely. - Time Complexity: Run in O(n) time.
- Space Complexity: Use O(1) extra space.
- Edge Cases: Correctly handle empty arrays or arrays containing a single element.
Candidates are expected to:
- Explain their chosen approach.
- Justify the uniformity of their algorithm at a high level.
- Analyze the time and space complexity of their solution.