Minimum Window Substring with Repeated Required Characters
Company: Lyft
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: Find the shortest substring covering every required character, including duplicates, with case-sensitive matching and a linear-time minimum-window algorithm.
Read the full Lyft Software Engineer interview experience this question came from
Constraints
- Both s and t have lengths from 1 through 100000 inclusive.
- Both strings contain only uppercase and lowercase English letters.
- Matching is case-sensitive and every target multiplicity must be satisfied.
- Return the shortest contiguous covering substring, or the empty string if none exists.
- Whenever a minimum window exists, the input guarantees a unique answer.
Examples
Input: ('ADOBECODEBANC', 'ABC')
Expected Output: 'BANC'
Explanation: The first source example has the uniquely shortest window BANC.
Input: ('a', 'aa')
Expected Output: ''
Explanation: The second source example has insufficient target multiplicity.
Hints
- Repeated target characters each contribute to the required multiplicity.
- A window must remain contiguous, even when it contains unneeded letters.