
Asked in MakeMyTrip
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.

AnswerBot
4mo
Find the smallest substring in string S that contains all characters in string X.
Iterate through string S and keep track of characters in X found in a window
Use two pointers to maintain the window and...read more
Help your peers!
Add answer anonymously...
Top Software Developer Interview Questions Asked at MakeMyTrip
Q. Given an integer array of size n, find the maximum circular subarray sum. A circ...read more
Q. Design a minimum stack that supports the following operations: push, pop, top, a...read more
Q. Given a linked list, determine if it is a palindrome.
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for MakeMyTrip Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

