1/13
Learn

Statistics across many nodes, the way the coding round asks

Anthropic coding rounds asked candidates for the mode and the median of data that sits on many nodes, through a messaging interface they were given (2 sources). This lesson's practice problem builds the whole answer, in three levels:

  1. summarize(values), merge(a, b) and mean_and_variance(summaries): each node sends its count, mean and spread, and the coordinator merges them into the exact mean and variance.
  2. global_mode(nodes): the most common value across every node, and the smallest one on a tie.
  3. distributed_median(nodes): the exact lower median, when each node only answers how many of its values are at or below v. The budget is about 12 rounds of questions.
CallReturns
merge((3, 10.0, 2.0), (1, 14.0, 0.0))(4, 11.0, 14.0)
mean_and_variance of the same two(11.0, 4.667)
global_mode([[3, 3, 5], [5, 7]])3: 3 and 5 tie at two each, and the smaller wins
distributed_median with nodes holding 5, 1, 9 and 3, 7, 23, the lower of the middle two

The lesson follows the shop's orders on 10 servers: merged means and variances, the mode, an exact median from count questions, and sketches for when exact costs too much. Six steps end with a small task in the editor.