Match readings with latest same-city humidity
Company: Two Sigma
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Technical Screen
## Problem
You are given two time-sorted lists of sensor readings:
- **Temperature** records: `(time, city, reading)`
- **Humidity** records: `(time, city, reading)`
Example:
**Temperature**
```text
[(1, 'NYC', 12),
(5, 'SFO', 20),
(7, 'NYC', 23),
(16, 'SFO', 10)]
```
**Humidity**
```text
[(0, 'SFO', 12),
(3, 'SFO', 2),
(6, 'NYC', 2),
(19, 'SFO', 9)]
```
### Task
For each temperature record, match it with the **most recent humidity record from the same city** whose `time <= temperature_time`.
- If there is no earlier humidity record for that city, return `null` (or `None`) for the humidity reading.
### Output
Return a list aligned to the temperature records, where each element includes the temperature record and the matched humidity reading (or `null`).
### Constraints
- Both input lists are individually sorted by time ascending.
- Cities may appear in any order within the global time ordering.
Quick Answer: This question evaluates the ability to align and join time-ordered sensor data by key, testing skills in time-series merging, per-key state management, and handling absent matches.