Solve sampling and streaming tasks
Company: Meta
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
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.
Deterministic Weighted Selection
Constraints
- draws are deterministic stand-ins for random integers in [0,total).
Examples
Input: ([1, 3, 2], [0, 1, 3, 4, 5])
Expected Output: [0, 1, 1, 2, 2]
Explanation: Cumulative buckets.
Input: ([5], [0, 99])
Expected Output: [0, 0]
Explanation: Single weight.
Hints
- Precompute prefix sums and binary-search each draw.
Find Anagram Windows
Examples
Input: ('cbaebabacd', 'abc')
Expected Output: [0, 6]
Explanation: Classic case.
Input: ('abab', 'ab')
Expected Output: [0, 1, 2]
Explanation: Overlapping windows.
Input: ('abc', 'abcd')
Expected Output: []
Explanation: Pattern longer than text.
Streaming Mean
Examples
Input: ((('mean',), ('add', 2), ('add', 4), ('mean',)),)
Expected Output: [None, 3.0]
Explanation: Empty then non-empty stream.
Input: ((('add', 1.5), ('mean',)),)
Expected Output: [1.5]
Explanation: Float value.