Solve substring and worker assignment
Company: Lyft
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: This pair of problems evaluates competencies in string processing and multiplicity handling as well as scheduling and resource-allocation for interval tasks, testing the ability to choose and apply appropriate data structures while managing time and space complexity.
Read the full Lyft Software Engineer interview experience this question came from
Part 1: Shortest Covering Substring
Constraints
- 0 <= len(s), len(t) <= 200000
- Characters are case-sensitive.
- The answer should account for repeated characters in t.
- If t is empty, return an empty string.
Examples
Input: ('ADOBECODEBANC', 'ABC')
Expected Output: 'BANC'
Explanation: 'BANC' is the shortest substring containing A, B, and C.
Input: ('bbaa', 'aba')
Expected Output: 'baa'
Explanation: The substring must contain two 'a' characters and one 'b'.
Hints
- Keep a frequency map of the characters required from t.
- Use a sliding window: expand the right side until the window is valid, then shrink the left side as much as possible.
Part 2: Minimum Worker Assignment
Constraints
- 0 <= len(jobs) <= 200000
- 0 <= start <= 10^9
- 0 <= duration <= 10^9
- Each job is a pair [start, duration].
- Intervals are half-open: [start, start + duration).
Examples
Input: [[0, 5], [1, 2], [6, 1]]
Expected Output: [0, 1, 0]
Explanation: The second job overlaps the first, so it needs a different worker. The third job can reuse worker 0.
Input: [[0, 3], [3, 2], [5, 1]]
Expected Output: [0, 0, 0]
Explanation: Because intervals are half-open, each job starts exactly when the previous one is free.
Hints
- Sort the jobs by start time, but remember each job's original index so you can rebuild the answer.
- Use one min-heap for busy workers by end time and another min-heap for currently available worker IDs.