Medium · System Design
Random Pick Index
Given an integer array nums that may contain duplicates, answer repeated pick(target) calls: return an index i with nums[i] == target, chosen uniformly at random among all such indices. The target always occurs in nums.
Examples
Example 1
[1,2,3,3,3] target 3Output: index 3
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.