PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Meta

Solve sampling and streaming tasks

Last updated: Apr 2, 2026

Quick Overview

This question evaluates algorithmic problem-solving, data structure design, probabilistic reasoning for weighted random selection, sliding-window string processing for anagram detection, and streaming/online statistical computation.

  • medium
  • Meta
  • Coding & Algorithms
  • Machine Learning Engineer

Solve sampling and streaming tasks

Company: Meta

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Implement the following algorithmic tasks: 1. **Weighted random selection**: You are given an array of positive integer weights `w`, where `w[i]` is the relative probability of selecting index `i`. Design a class with: - a constructor that preprocesses `w` - a method `pickIndex()` that returns an index such that the probability of returning `i` is `w[i] / sum(w)` Aim for fast repeated sampling. 2. **Find anagram windows**: Given two strings `s` and `p`, return all starting indices in `s` where the substring of length `len(p)` is an anagram of `p`. 3. **Streaming mean**: Design a data structure for a stream of numbers that supports: - `add(x)`: add a new number to the stream - `getMean()`: return the arithmetic mean of all numbers seen so far Discuss edge cases such as an empty stream and large input volume.

Quick Answer: This question evaluates algorithmic problem-solving, data structure design, probabilistic reasoning for weighted random selection, sliding-window string processing for anagram detection, and streaming/online statistical computation.

Related Interview Questions

  • Solve Two Backtracking Array Problems - Meta (hard)
  • Solve Array, Matrix, and Recommendation Problems - Meta (medium)
  • Find a String Containing Another - Meta (medium)
  • Solve Subarray Sum and Local Minimum - Meta (hard)
  • Validate abbreviations and brackets - Meta (medium)
Meta logo
Meta
Sep 4, 2025, 12:00 AM
Machine Learning Engineer
Onsite
Coding & Algorithms
0
0
Loading...

Implement the following algorithmic tasks:

  1. Weighted random selection : You are given an array of positive integer weights w , where w[i] is the relative probability of selecting index i . Design a class with:
    • a constructor that preprocesses w
    • a method pickIndex() that returns an index such that the probability of returning i is w[i] / sum(w) Aim for fast repeated sampling.
  2. Find anagram windows : Given two strings s and p , return all starting indices in s where the substring of length len(p) is an anagram of p .
  3. Streaming mean : Design a data structure for a stream of numbers that supports:
    • add(x) : add a new number to the stream
    • getMean() : return the arithmetic mean of all numbers seen so far Discuss edge cases such as an empty stream and large input volume.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Meta•More Machine Learning Engineer•Meta Machine Learning Engineer•Meta Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

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

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL 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.