Implement minimum window substring with counts
Company: DoorDash
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Implement a function min_window_with_counts(s: str, t: str) -> tuple[int,int] that returns the (start_index, end_index) of the shortest substring of s containing all characters in t with at least their required multiplicities. Constraints and rules:
- ASCII strings; case-sensitive; indices are 0-based; return (-1, -1) if no window exists.
- The window cannot skip characters; whitespace and punctuation in s count as normal characters.
- If multiple windows have the same minimal length, return the one with the smallest start index; if still tied, the one with the smallest end index.
- Time complexity must be O(n) and space O(Σ) using a sliding window and frequency maps; do not sort or use nested scans over s.
- You must handle large inputs (len(s) up to 2e6) without quadratic behavior.
Provide at least 3 test cases, including:
1) s = "ADOBECODEBANC", t = "ABC" -> expected (9, 12) for "BANC".
2) s = "aAaBbBc", t = "Aab" -> expected (0, 3) for "aAaB" (meets counts: A×2, a×1, b×1) or any equally minimal valid window following tie-breaking.
3) s = "xyzzzy", t = "zz" -> expected (2, 3). Explain how your code maintains counts and a satisfied counter.
Quick Answer: This question evaluates understanding of sliding-window algorithms, frequency/count maps, handling character multiplicities and case sensitivity in string processing, along with attention to tie-breaking by indices and linear-time/space constraints.