Sample index from probability distribution | LinkedIn Interview Question