Smallest Window Problem Statement
Given two strings, S
and X
, your task is to find the smallest substring in S
that contains all the characters present in X
.
Example:
Input:
S = "abdd", X = "bd"
Output:
"bd"
Explanation:
The substrings in S
that contain all the characters in X
are: "abdd", "abd", "bdd", "bd". Among these, "bd" is the smallest substring.
Constraints:
1 <= T <= 10
1 <= |S|, |X| <= 10^5
- Time Limit: 1 sec
Input:
The first line contains an integerT
, the number of test cases.
Each test case consists of two lines:
- First line contains the stringS
.
- Second line contains the stringX
.
Output:
For each test case, print the smallest window inS
containing all characters ofX
, on a separate line.
Note:
- There is always a valid window in
S
that contains all characters ofX
. - If there are multiple smallest windows, return the one that appears first.
Be the first one to answer
Add answer anonymously...
Top MakeMyTrip Software Developer interview questions & answers
Popular interview questions of Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app