This multipart question evaluates skills in tokenization and streaming text processing, generic rooted-tree data-structure design and traversal APIs, dictionary-based string segmentation (dynamic programming and prefix/prefix-structure optimization), and constrained algorithmic optimization for stock-trading problems.

You have four tasks: