Fredo and Two Strings

4.2

8 votes
Algorithms, Dynamic Programming, Medium, String Manipulation
Problem

Fredo has got two strings s and t. Playing around with them, he came up with the following question:
Will string t be a subsequence of string s if he removes substring [si,si+1,....,sj1,sj] from string s ?

Given q queries, each query consists of indices i and j, you have to answer "Yes" if string t is a subsequence of remaining string s else answer "No".

Note:
Each query is independent of each other.

Input Format:

First line of input consists of string s.
Next line consists of string t.
Next line consists of two integers q 2 (q denoting number of queries and second integer always having value 2).
Each of following q lines consists of two integers i and j, denoting starting and ending indices of substring to be deleted from string s.

Output Format:
For each query , output "Yes" if t is a subsequence of remaining string s, else output "No".
Answer for each query should come in a new line.

Input Constraints:

1|s|105
1|t||s|
1q105
1ij|s|
Both strings s and t contain lowercase English alphabets.

Sample Input
abcabcxy
ax
2 2
2 6
6 7
Sample Output
Yes
No
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Query 1: Remaining string s= "axy", clearly "ax" is a subsequence of this string.

Query 2: Remaining string s="abcaby", clearly "ax" is not a subsequence of this string.

Editor Image

?