Neural Mastery
← Practice
Fan-In Aggregation of Parallel Branch Resultsmedium

Fan-In Aggregation of Parallel Branch Results

medium Agents in Production 15 min

NumPy allowed · plain Python earns 10 bonus points

Interactive
Graph & Tree Traversal, Step by Step
Structure
Algorithm
ABCDE
visiting A -> visited order so far: [A]
queue now: [B, C]
Step 1 / 5
Both modes run the real algorithm from the linked practice problem, one step at a time -- edit the graph or pick different tree nodes and every step recomputes live.

Implement fan-in aggregation, collecting multiple parallel branches' results back into one combined value when they rejoin at a shared downstream node.

Task

Implement fan_in_aggregate(branch_results, aggregation_key). branch_results maps branch name -> that branch's partial state dict. Return the list of aggregation_key values from each branch (only including branches that actually have that key), sorted by branch name for determinism.

Function Signature

fan_in_aggregate(branch_results: dict[str, dict], aggregation_key: str) -> list

Examples

Example 1: three branches all with the key
Input: branch_results = {'b': {'score': 2}, 'a': {'score': 1}, 'c': {'score': 3}} aggregation_key = 'score'
Output: [1, 2, 3]
Example 2: one branch missing the key
Input: branch_results = {'a': {'score': 1}, 'b': {}} aggregation_key = 'score'
Output: [1]
Example 3: single branch
Input: branch_results = {'only': {'score': 5}} aggregation_key = 'score'
Output: [5]

Constraints

  • branch_results is a dict of dicts
Python3Saved ✓
def fan_in_aggregate(branch_results, aggregation_key):
# Your implementation here
pass

Case 1: three branches all with the key
Input: branch_results = {'b': {'score': 2}, 'a': {'score': 1}, 'c': {'score': 3}} aggregation_key = 'score'
Expected: [1, 2, 3]
Case 2: one branch missing the key
Input: branch_results = {'a': {'score': 1}, 'b': {}} aggregation_key = 'score'
Expected: [1]
Case 3: single branch
Input: branch_results = {'only': {'score': 5}} aggregation_key = 'score'
Expected: [5]