The Suffix Matches
Practice
2.4 (7 votes)
Algorithms
Approved
Arrays
Data structures
Medium
Open
Problem
60% Success 1065 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Rob needs to give a string to each of his students. There is huge string S that is known to all. He doesn't want to work much, hence decides to give each of them, some prefix of S.

Now, the students consider their strings holy, if their string is very similar to this known string S. Now, this similarity comparison is done from suffix matching.

So, now you are to help in this computation. So, given an integer i, find the longest matching suffix in between S[1...i] and S.

Input:
The first line contains string S. The next line contains q, the number of queries. Each of the following q lines contain a number i, denoting the query.

Output:
Output q lines each containing the answer as explained above.

Constraints:
1 <= |S| <= 200000
1 <= q <= |S|
1 <= i <= |S|

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
No similar problems found