398 Random Pick Index
398. Random Pick Index
1. Question
Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that the given target number must exist in the array.
Note: The array size can be very large. Solution that uses too much extra space will not pass the judge.
Example:
2. Implementation
(1) Reservoir Sampling
3. Time & Space Complexity
Reservoir Sampling: 时间复杂度O(n), 空间复杂度O(n)
Last updated