Some museum audio guide captions change when batches are merged
Level 2 · node · Data · Missing global index remapping when merging batch-local dictionaries
Scenario
A fictional museum stores a string dictionary and integer indices for each batch of audio guide captions to reduce repeated phrases. Individual batches play correctly, but some captions display different phrases after batches with different dictionaries are combined. Review the data contracts of the dictionary builder, merger and preview flow together.
Requirements
combine(batches) returns {dictionary, codes}. Each batch has a dictionary of unique strings and codes consisting of valid zero-based indices into that batch's dictionary or null for a missing caption. The output dictionary contains only the first occurrence of each phrase while traversing all input dictionaries in batch order and then dictionary order (including unused phrases). Output codes must refer to the output dictionary while preserving batch and caption order and nulls. decode(result) returns an array of the corresponding phrases or nulls. Handle empty input and do not mutate originals.
Acceptance criteria
- Decode batches with identical dictionaries in input order.
- Decode the correct phrases even when batch dictionaries have different orders.
- Merge partially overlapping dictionaries in first-occurrence order and preserve missing caption positions.
- Handle empty input and unused dictionary entries without changing original data.