Parse strings and find meeting slots
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: This question evaluates string parsing and data-extraction skills alongside set/array-based aggregation and algorithmic reasoning for calendar availability and time-window constraints.
Constraints
- 1 <= len(lines) <= 200000
- Each line contains exactly one user identifier of the form '@[A-Za-z0-9_]+' and exactly one signed integer (e.g., -7, +3, 42)
- 1 <= len(calendars) <= 100000
- Let T be the total number of day entries across all users in calendars; 0 <= T <= 200000
- Day values are integers in [1, 10^9]
- Duplicates in a single user's day list are allowed but count once for that user
- 1 <= p <= len(calendars)
- 1 <= x <= 10^6
- Output 'days' must be sorted ascending without duplicates
- Output 'periods' must be sorted by start ascending; each period is [start, end] inclusive with end = start + x - 1
Hints
- Use a regular expression to extract '@username' and the (signed) integer from each line; strip the leading '@' from the username.
- Aggregate per-user sums in a dictionary for O(1) average updates.
- Convert each user's availability list to a set to remove duplicates before counting days.
- Count availability per day across users, then collect days with count >= p and sort them.
- Scan the sorted valid days to find consecutive runs and emit all length-x windows within each run.