The One With The Queries

3.8

63 votes
Easy
Problem

You are given a string S and Q query strings (q1, q2, ... , qQ). For each query string, report whether or not it is a subsequence of S.

Input :

The first line contains a string S.

The next line contains a single integer, Q.

The following Q lines each contain 1 query string qi.

Output :

Output Q lines. On the ith line print "Yes" (without quotes) if qi is a sub-sequence of S, otherwise print "No" (without quotes).

Constraints :

1 <= |S|, |q[i]|, Q <= 100,000

Sum of lengths of all query strings <= 1,000,000

All strings consist of lowercase english letters only. ('a'-'z')

Time Limit: 2
Memory Limit: 256
Source Limit:
Editor Image

?