← Questions

Random pick with weight

0
MetaGoogleCodingLast asked Oct 2026

A coding interview question asked in Google's onsite coding round and at Meta, last asked Oct 2026. It tests prefix sums, binary-search and randomized.

You get positive integer weights, one per index. Build a sampler whose pick() returns index i with probability w[i] / sum(w).

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

  • Google · Onsite coding · Last asked Oct 202645 min · Usually two rounds, mostly in person: whiteboard plus a Chromebook with Google Docs · No AI (a pilot code-comprehension round lets candidates use Gemini)
  • Meta · AI-enabled coding · Last asked Oct 202560 min · Several progressive tasks on a starter codebase in CoderPad with an AI assistant panel; usually two rounds · The first task usually without AI, later tasks with it

What it tests

prefix sums · binary-search · randomized

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