← Questions

Random pick weighted by population

0
AppleMetaCodingLast asked Jul 2026

A coding interview question asked in Apple's technical phone screen and at Meta, last asked Jul 2026. It tests randomization, prefix sums and binary-search.

Given a fixed list of countries and their populations, build a picker that returns a random country with probability proportional to its population. The picker is built once and then called many times.

Sign in to unlock this question

The full prompt, the worked answer and your own canvas or code with the AI tutor. New accounts get 5 credits: each one unlocks a question for good.

Where it's asked

  • Apple · Technical phone screen · Last asked Jul 2026
  • Meta · Technical phone screen · Last asked Feb 202645 min · Two coding problems in CoderPad, about 20 minutes each · Usually no AI; some newer screens are AI-assisted

What it tests

randomization · prefix sums · binary-search

Your code and the AI tutor open when you unlock this question.