Merge Shard Statistics
~20 mincode completion
Implement merge_stats(nA, meanA, varA, nB, meanB, varB) returning (n, mean, variance) as a tuple.
Examples
Two equal shards [1,2,3] and [4,5,6]: merged mean=3.5
- Input
- merge_stats(3, 2, 0.6667, 3, 5, 0.6667)
- Output
- [6, 3.5, 2.9167]
Merging with a single-element shard of known value
- Input
- merge_stats(2, 3, 1, 1, 6, 0)
- Output
- [3, 4, 2.66667]
Identical shards: merged mean equals shard mean
- Input
- merge_stats(4, 5, 2, 4, 5, 2)
- Output
- [8, 5, 2]
Hints
Hint 1
Work directly with the arguments nA, meanA, varA, nB, meanB, varB and return the result rather than printing it.
Hint 2
Watch for this: computed simple average of means not weighted.
Requirements
Return Tuple (n, mean, variance) for the combined dataset.
Constraints
Standard library only, no imports required
Time limit: 200 ms, Memory: 64 MB
Where this shows up
~20 min
••••••••••••••••
8 employers weight this skill
4 big tech firms, 1 AI product company, 1 enterprise vendor, 1 defense company, 1 quant fund. Top match scores 92.
Python
def merge_stats(nA: int, meanA: float, varA: float,
nB: int, meanB: float, varB: float) -> tuple:
"""
Merge mean and population variance statistics from two data shards.
Returns:
Tuple (n, mean, variance) for the combined dataset.
"""
# YOUR CODE HERE
pass