Fredo and Two Strings
Practice
4.2 (8 votes)
Algorithms
Dynamic programming
Medium
String manipulation
Problem
43% Success 2627 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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 \([s_i,s_{i+1},....,s_{j-1},s_j]\) 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 \le |s| \le 10^5\)
\(1 \le |t| \le |s|\)
\(1 \le q \le 10^5\)
\(1 \le i \le j \le |s|\)
Both strings s and t contain lowercase English alphabets.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
7 votes
Tags:
AlgorithmsC++Dynamic Programming
Points:30
10 votes
Tags:
AlgorithmsDynamic ProgrammingIntroduction to Dynamic Programming 1
Points:30
10 votes
Tags:
ApprovedBrute-force searchMathMediumOpen