Solve substring and worker assignment
Company: Lyft
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: 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.
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'.
Input: ('abdcab', 'ab')
Expected Output: 'ab'
Explanation: There are two shortest valid windows of length 2; return the earlier one.
Input: ('a', 'aa')
Expected Output: ''
Explanation: s does not contain enough copies of 'a'.
Input: ('abc', '')
Expected Output: ''
Explanation: An empty target requires no characters, so return the empty string.
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.
Input: [[2, 4], [2, 1], [3, 2], [7, 1]]
Expected Output: [0, 1, 1, 0]
Explanation: Two workers are enough. Jobs are processed by start time, and the smallest free worker ID is reused.
Input: []
Expected Output: []
Explanation: No jobs means no assignments.
Input: [[1, 0], [1, 0], [1, 1]]
Expected Output: [0, 0, 0]
Explanation: Zero-duration jobs occupy no time, so the same worker can be reused immediately.
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.