Allocate Homepage Widget Slots With Thompson Sampling

Last updated: November 29, 2026

Quick Overview

You have several candidate homepage widgets (deals, recently viewed, new releases) and want to learn which earns the most clicks while still serving traffic well. Explain and implement a Thompson sampling approach.

Amazon
Machine Learning
Data Scientist
Amazon
November 29, 2026
Data Scientist
Technical Screen
Machine Learning
Medium

0

0

0 solved


You have several candidate homepage widgets (deals, recently viewed, new releases) and want to learn which earns the most clicks while still serving traffic well. Explain and implement a Thompson sampling approach.

Amazon pages are assembled from many competing widgets, and bandits are a natural fit for allocating them. The interviewer wants to see you contrast bandits with fixed A/B tests, implement Beta-Bernoulli Thompson sampling, and reason about non-stationarity.

What the Interviewer Expects
  • Frame as a multi-armed bandit with Bernoulli rewards
  • Implement Beta posterior updates
  • Explain why sampling balances exploration and exploitation
  • Discuss delayed and non-stationary rewards
  • Contrast with a fixed-split A/B test
Key Topics to Cover
Multi-armed bandits
Thompson sampling
Beta distribution
Exploration vs exploitation
Non-stationarity
How to Approach This
  1. Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
  2. Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
  3. Feature engineering is often more impactful than model selection.
  4. Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
  5. Handle class imbalance with SMOTE, class weights, or appropriate loss functions.
Possible Follow-up Questions
  • How would you make it contextual, using customer segment?
  • How do you handle reward delays when the reward is a purchase hours later?
  • How would you report a final 'winner' to stakeholders?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Explore ML Interview Prep
Sample Answer
Clarify

Confirm the reward (click on the widget, binary) and that arms are fixed for the experiment period. Ask whether we need a clean causal estimate (A/B test) or want to minimize regret while learning (ba...

Approach

Give each arm a Beta(1, 1) prior on click rate. On each request draw θa∼Beta(αa,βa)\theta_a\sim\text{Beta}(\alpha_a,\beta_a), show the arm with the largest draw, and update α\alpha on a click or β\beta otherwis...


Submit Your Answer
Markdown supported