PracHub
QuestionsLearningGuidesInterview Prep
|Home/Statistics & Math/OpenAI

Maintain Entropy for a Streaming Distribution

Last updated: Jul 28, 2026

Quick Overview

Maintain empirical Shannon entropy after every categorical observation without rescanning all categories. The discussion should cover arbitrary identifiers, first-item behavior, exact counts, floating-point drift, concurrency, deletions, sliding windows, and merging summaries from separate stream partitions.

  • medium
  • OpenAI
  • Statistics & Math
  • Machine Learning Engineer

Maintain Entropy for a Streaming Distribution

Company: OpenAI

Role: Machine Learning Engineer

Category: Statistics & Math

Difficulty: medium

Interview Round: Onsite

A stream emits categorical observations one at a time. After each observation, report the empirical Shannon entropy of all observations seen so far: `H = -sum(p_i * log(p_i))`, where `p_i` is the observed frequency of category `i` divided by the total count. Use natural logarithms. Design an update algorithm that does not rescan every category after each arrival. Explain the state you maintain, derive the update formula, and discuss numerical behavior. Categories may be arbitrary hashable identifiers. ### Constraints & Assumptions - The stream is initially empty; entropy after the first item is zero. - Exact integer category counts fit in the chosen integer type. - Small floating-point rounding differences are acceptable. - The output is required after every insertion. ### Clarifying Questions to Ask - Is the logarithm base prescribed? Natural log for this problem. - Are deletions or a sliding window required? Not initially. - Is an approximate sketch acceptable? No for the base problem. ### What a Strong Answer Covers - Algebraic reformulation using counts - Constant expected update time plus hash-map storage - Correct treatment of a new category and count zero - Numerical and concurrency considerations ### Follow-up Questions - Support deletion of an observation. - Maintain entropy over a fixed-size sliding window. - Merge summaries computed independently on several stream partitions.

Quick Answer: Maintain empirical Shannon entropy after every categorical observation without rescanning all categories. The discussion should cover arbitrary identifiers, first-item behavior, exact counts, floating-point drift, concurrency, deletions, sliding windows, and merging summaries from separate stream partitions.

Related Interview Questions

  • Derive MLE and Bayesian posterior for Bernoulli - OpenAI (medium)
|Home/Statistics & Math/OpenAI

Maintain Entropy for a Streaming Distribution

OpenAI logo
OpenAI
Aug 23, 2025, 12:00 AM
mediumMachine Learning EngineerOnsiteStatistics & Math
2
0

A stream emits categorical observations one at a time. After each observation, report the empirical Shannon entropy of all observations seen so far:

H = -sum(p_i * log(p_i)), where p_i is the observed frequency of category i divided by the total count. Use natural logarithms.

Design an update algorithm that does not rescan every category after each arrival. Explain the state you maintain, derive the update formula, and discuss numerical behavior. Categories may be arbitrary hashable identifiers.

Constraints & Assumptions

  • The stream is initially empty; entropy after the first item is zero.
  • Exact integer category counts fit in the chosen integer type.
  • Small floating-point rounding differences are acceptable.
  • The output is required after every insertion.

Clarifying Questions to Ask Guidance

  • Is the logarithm base prescribed? Natural log for this problem.
  • Are deletions or a sliding window required? Not initially.
  • Is an approximate sketch acceptable? No for the base problem.

What a Strong Answer Covers Guidance

  • Algebraic reformulation using counts
  • Constant expected update time plus hash-map storage
  • Correct treatment of a new category and count zero
  • Numerical and concurrency considerations

Follow-up Questions Guidance

  • Support deletion of an observation.
  • Maintain entropy over a fixed-size sliding window.
  • Merge summaries computed independently on several stream partitions.
Loading comments...

Browse More Questions

More Statistics & Math•More OpenAI•More Machine Learning Engineer•OpenAI Machine Learning Engineer•OpenAI Statistics & Math•Machine Learning Engineer Statistics & Math

Write your answer

Your first approved answer each day earns 20 XP.

Sign in to write your answer.
PracHub

Master your tech interviews with 9,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.