Design a Population-Weighted Random Country Picker

Quick Overview

Design an immutable weighted random country picker whose selection probability is proportional to population. Precompute cumulative integer weights, draw uniformly over the total range, and use boundary-safe binary search with injectable randomness for deterministic tests.

Design a Population-Weighted Random Country Picker

Company: Apple

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Technical Screen

Overview: Design an immutable weighted random country picker whose selection probability is proportional to population. Precompute cumulative integer weights, draw uniformly over the total range, and use boundary-safe binary search with injectable randomness for deterministic tests.

|Home/Software Engineering Fundamentals/Apple
Apple logo
Apple
Jul 2, 2026
mediumSoftware EngineerTechnical ScreenSoftware Engineering Fundamentals
8
0
Loading...
Loading comments...