https://leetcode.com/problems/random-pick-index/description/
Reservoir Sampling
class Solution { public: vector<int> m; Solution(vector<int> nums) { m = nums; } int pick(int target) { int res = -1; for (int i = 0, cnt = 0; i < m.size(); i++) { if (m[i] == target) { cnt++; if (rand() % cnt == 0) res = i; } } return res; } };