Find substring
Practice
2.4 (7 votes)
Hash function
Easy
String
Hashing algorithm
Problem
57% Success 5015 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given two strings A and B. You have to find smallest substring of A such that it contains all the letters of string B. The letters in both the strings can be any ASCII character.

Input constraints
\(1 \le T \le 1000\)
\(1 \le |A| \le 1000\) where A denotes the length of the string A.
\(1 \le |B| \le 1000\) where B denotes the length of the string B.

Input format
First line contains an integer, T,denoting the number of test cases.
First line in each test case contains a string, A.
Second line in each test case contains a string B.

Output format
Print the smallest substring of A such that it contains all the letters of string B. If there is no such substring, print 1. If there are multiple such substring, print the one which starts first. Answer for each test case should be in a new line.

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:20
7 votes
Tags:
String AlgorithmsHashing AlgorithmAlgorithms
Points:20
369 votes
Tags:
Ad-HocString AlgorithmsHash functionEasyVery Easy
Points:20
10 votes
Tags:
StringImplementationRecruitBasic ProgrammingAlgorithmsEasyString AlgorithmsApprovedHashing algorithmHashing algorithm