Implement the partition
Describe the data structures and the single pass that produce the partition, with its time and space cost. Explain how the output stays stable when more than one phrase could match the same string.
Is the implementation concrete enough to reproduce, including how ties are broken?