PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/DoorDash

Implement minimum window substring with counts

Last updated: Mar 29, 2026

Quick Overview

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.

  • medium
  • DoorDash
  • Coding & Algorithms
  • Data Scientist

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.

Related Interview Questions

  • Maximize Chef Assignment Profit - DoorDash (medium)
  • Compute Courier Delivery Pay - DoorDash (easy)
  • Compute Nearest Destination Distances - DoorDash (easy)
  • Count changed nodes between two menu trees - DoorDash (hard)
  • Calculate Daily Driver Pay - DoorDash (hard)
DoorDash logo
DoorDash
Oct 13, 2025, 9:49 PM
Data Scientist
Technical Screen
Coding & Algorithms
6
0

Implement min_window_with_counts(s, t)

Task

Write a function:

  • min_window_with_counts(s: str, t: str) -> tuple[int, int]

that returns the inclusive (start_index, end_index) of the shortest substring of s containing all characters in t with at least their required multiplicities.

Rules and Constraints

  • ASCII strings; case-sensitive; indices are 0-based.
  • Return (-1, -1) if no such window exists.
  • The window is contiguous (cannot skip characters); whitespace and punctuation 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.
  • Must handle large inputs (len(s) up to 2e6) without quadratic behavior.
  • Assume t is non-empty; if t is empty, treat as no window and return (-1, -1).

Deliverables

  • The function implementation using a linear-time sliding window with frequency maps and a satisfied counter.
  • At least 3 test cases including the ones below.

Required Test Cases

  1. s = "ADOBECODEBANC", t = "ABC" → expected (9, 12) for substring "BANC".
  2. s = "aAaBbBc", t = "Aab" → the minimal valid window is (1, 4) for substring "AaBb". Note: the prompt’s illustrative substring "aAaB" at (0, 3) does not contain the required lowercase 'b', so it is not valid under case-sensitive matching.
  3. s = "xyzzzy", t = "zz" → expected (2, 3) for substring "zz". Explain how counts and the satisfied counter are maintained.

Solution

Show

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More DoorDash•More Data Scientist•DoorDash Data Scientist•DoorDash Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.