Introduction
A string data structure is one of the basic data structures for competitive programming. One should be clear with the methods related to string for reducing the complexity of the problems.
This problem is where we will be checking whether the given string is the substring of the actual string or not with some constraints.
A substring is a sequence of contiguous characters within a string.
Let’s quickly move on to our problem statement for more clarity.
Problem Statement
We are provided with a string ‘s’ followed by the number of queries ‘q,’ and each query has some string ‘t.’ We aim to find whether ‘t’ is the substring of ‘s’ or not.
If ‘t’ is the substring of string ‘s,’ print ‘y’ else ‘n.’
Constraints
- The string ‘s’ length should not be more than 10000.
- ‘q’ < 1000.
- ‘t’ of maximum length 1,000.
- Characters in the string will have ‘a’-‘z’ and ‘A’-‘Z’ in the range.
Let’s understand this with the help of some examples.
Example 1:
Input: s=abcdEFGH
3
ab
cdE
abEF
Output:
y
y
n
Explanation:
Here s = abcdEFGH, q = 3(means three strings will be given to check), t = ab, cdE, abEF
Now we aim to check whether these substrings are part of the string ‘s’ or not.
So, ab is a substring of abcdEFGH, cdE is also a substring of abcdEFGH, and abEF is not a substring of abcdEFGH.
Example 2:
Input: s = xyzTU
1
yz
Output:
y
Explanation:
Here s = xyzTU, q = 1(means one string will be given to check), t = yz. Now, we aim to check whether this substring is part of the string ‘s’ or not.
So, yz is a substring of xyzTU.
If you are clear with what the question says and your aim, they first try to solve it on your own.