Operations on strings

0

0 votes
Dynamic Programming, Algorithms, String, Introduction to Dynamic Programming 1, Open, Medium
Problem

You are given two strings s and t. You are also given the following operation to perform:

Is string t a subsequence of string s if you remove [si,si+1,....,sj1,sj] substring from string s.

You are given q queries. Each query consists of indices i and j. If string t is a subsequence of the remaining string s, you are required to print Yes. Otherwise, print No.

Note: Each query is independent of each other.

Input format

  • First line: String s
  • Next line: String t
  • Next line: Two integers q 2 where q denotes the number of queries and the second integer contains value 2
  • Each of following q lines: Two integers i and j denoting the starting and ending indices of the substring that must be deleted from string s

Output format
If string t is a subsequence of the remaining string s, you are required to print Yes. Otherwise, print No.
The answer for each query should come in a new line.

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

?