DSA interview question
A log-forensics tool looks for the shortest contiguous stretch of a log in which a given sequence of events T happens in order, with other events possibly in between. That's a window of S that contains T as a subsequence. Return the shortest such window, the leftmost one if several tie, or "" if none exists. A forward scan finds the earliest end where T is completed. A backward scan from that end, matching T in reverse, finds the latest possible start, which gives the tightest window ending there. Then search again starting just after that start.
Example: S = "abcdebdde", T = "bde" → "bcde".
string minWindowSubsequence(const string& S, const string& T); // T non-empty; "" if none
Input (S, T) | Output | Explanation |
|---|---|---|
("abcdebdde", "bde") | "bcde" | "bdde" is also length 4 but starts later |
("abdbca", "ba") | "bca" | |
("aaa", "aa") | "aa" | Leftmost of the ties |
("xyz", "zy") | "" | Order matters |
("abc", "abc") | "abc" |
(Confirm: T must appear as a subsequence (in order, gaps allowed) inside a contiguous window of S; ties go to the leftmost window.)
On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in