Match readings with latest same-city humidity

Quick Overview

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.

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.

|Home/Coding & Algorithms/Two Sigma
Two Sigma logo
Two Sigma
Dec 15, 2025, 12:00 AM
easyData ScientistTechnical ScreenCoding & Algorithms
15
0

Problem

You are given two time-sorted lists of sensor readings:

  • Temperature records: (time, city, reading)
  • Humidity records: (time, city, reading)

Example:

Temperature

[(1,  'NYC', 12),
 (5,  'SFO', 20),
 (7,  'NYC', 23),
 (16, 'SFO', 10)]

Humidity

[(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.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...