Great solution! And I think there is an improvement:
It is not always true that each string could be the starting word of a row. For example:
In this example, only times("as") and times("bn") were used.
It is a waste of time especially when the number of strings in sentence is way bigger than rows.
So my suggestion is to encapsulate the process of calculating nextIndex and times to a function. And call it as needed. Of course there is a memorization to avoid repeated calculation.