123 - Searching Quickly

You may build an index from keyword to a sorted list of positions to solve this problem.

A position is pair (i, j) that points to the j-th word of the i-th input line. The list of positions is sorted first by i and then by j so that the output order satisfies problem description.

A reference soution is here.

Creative Commons License
This blog by Che-Liang Chiou is licensed under a Creative Commons Attribution 4.0 International License.