Amazon Interview Question

Code a weighted distribution function so that it returns selection w probability according to weights. Similar to one on leetcode