How to solve the problem A6?

Here is the link to the question:

Since the sequence b is infinitely long, how will I know if certain sub sequences don’t exist in b(as indicated by the -1s in the sample test case).
Also, what efficient way should I use to match the sub sequence to the main sequence? Should I use some string matching algorithm like Rabin Karp?