PracHub
QuestionsLearningGuidesInterview Prep
|Home/Statistics & Math/Citadel

Compute Statistics from a Frequency Array

Last updated: Jul 14, 2026

Quick Overview

Compute count, minimum, maximum, mean, median, mode, and population standard deviation directly from a 256-bin frequency array. Use weighted moments and cumulative ranks without expanding samples, define empty-data behavior and ties, and address overflow and numerical precision.

  • hard
  • Citadel
  • Statistics & Math
  • Software Engineer

Compute Statistics from a Frequency Array

Company: Citadel

Role: Software Engineer

Category: Statistics & Math

Difficulty: hard

Interview Round: Technical Screen

# Compute Statistics from a Frequency Array You receive an array `freq` of length 256. `freq[v]` is the number of times integer value `v` occurs in an implicit data set. For example, `[2, 5, 8]` represents two zeroes, five ones, and eight twos. Without expanding the implicit data set, explain how you would compute its count, minimum, maximum, arithmetic mean, median, mode, and population standard deviation. Give the time and extra-space complexity and define the behavior for an empty data set. ### Constraints & Assumptions - Every frequency is a non-negative integer. - The total count and weighted sums may require wider numeric types than an individual frequency. - If multiple values share the largest frequency, report the smallest as the mode. - For an even count, the median is the average of the two middle observations. - Return “undefined” for value-based statistics when the total count is zero. ### Clarifying Questions to Ask - Is population or sample standard deviation required? - How should ties for the mode be resolved? - What numeric precision and overflow behavior are expected? - What should the API return for an empty data set? ### Solving Hints - Most statistics are weighted sums or positions in cumulative frequency. - The two median ranks can be located during a single cumulative scan. - A variance formula based on two weighted moments avoids materializing samples. ### What a Strong Answer Covers - Correct formulas and zero-based or one-based median-rank handling. - A clear empty-input contract and deterministic mode tie-breaking. - Overflow and floating-point precision considerations. - `O(256)` time and `O(1)` extra space, generalized to `O(m)` for `m` bins. - An explanation of why the implicit data set must not be expanded. ### Follow-up Questions 1. How would you merge statistics from frequency arrays computed on separate machines? 2. When can `E[X^2] - E[X]^2` lose numerical precision, and what alternative would you use? 3. How would the algorithm change if values were arbitrary sparse integers rather than `0..255`? 4. How would you compute a requested percentile?

Quick Answer: Compute count, minimum, maximum, mean, median, mode, and population standard deviation directly from a 256-bin frequency array. Use weighted moments and cumulative ranks without expanding samples, define empty-data behavior and ties, and address overflow and numerical precision.

Related Interview Questions

  • Solve probability and stopping questions - Citadel (hard)
  • Solve Classic Probability Questions - Citadel (hard)
  • Find constant minimizing absolute error - Citadel (easy)
  • Solve probability and expectation problems - Citadel (hard)
|Home/Statistics & Math/Citadel

Compute Statistics from a Frequency Array

Citadel logo
Citadel
Mar 29, 2026, 12:00 AM
hardSoftware EngineerTechnical ScreenStatistics & Math
3
0

Compute Statistics from a Frequency Array

You receive an array freq of length 256. freq[v] is the number of times integer value v occurs in an implicit data set. For example, [2, 5, 8] represents two zeroes, five ones, and eight twos.

Without expanding the implicit data set, explain how you would compute its count, minimum, maximum, arithmetic mean, median, mode, and population standard deviation. Give the time and extra-space complexity and define the behavior for an empty data set.

Constraints & Assumptions

  • Every frequency is a non-negative integer.
  • The total count and weighted sums may require wider numeric types than an individual frequency.
  • If multiple values share the largest frequency, report the smallest as the mode.
  • For an even count, the median is the average of the two middle observations.
  • Return “undefined” for value-based statistics when the total count is zero.

Clarifying Questions to Ask Guidance

  • Is population or sample standard deviation required?
  • How should ties for the mode be resolved?
  • What numeric precision and overflow behavior are expected?
  • What should the API return for an empty data set?

Solving Hints

  • Most statistics are weighted sums or positions in cumulative frequency.
  • The two median ranks can be located during a single cumulative scan.
  • A variance formula based on two weighted moments avoids materializing samples.

What a Strong Answer Covers Guidance

  • Correct formulas and zero-based or one-based median-rank handling.
  • A clear empty-input contract and deterministic mode tie-breaking.
  • Overflow and floating-point precision considerations.
  • O(256) time and O(1) extra space, generalized to O(m) for m bins.
  • An explanation of why the implicit data set must not be expanded.

Follow-up Questions Guidance

  1. How would you merge statistics from frequency arrays computed on separate machines?
  2. When can E[X^2] - E[X]^2 lose numerical precision, and what alternative would you use?
  3. How would the algorithm change if values were arbitrary sparse integers rather than 0..255 ?
  4. How would you compute a requested percentile?
Loading comments...

Browse More Questions

More Statistics & Math•More Citadel•More Software Engineer•Citadel Software Engineer•Citadel Statistics & Math•Software 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 8,500+ 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.