Compute party time blocks per neighborhood
Scale AISoftware Engineer · OnsiteLast updated
This question evaluates a candidate's ability to perform interval merging and temporal aggregation across joined datasets, testing algorithmic efficiency, data-processing skills, and handling of sorting and grouping in the Coding & Algorithms domain.
You are given two datasets:
- Parties:
party_id(string or integer)start_timestamp(e.g., UNIX timestamp or datetime)end_timestamp(same type asstart_timestamp, andend_timestamp > start_timestamp)
- PartyLocations:
party_idneighborhood(string)city(string)state(string)
Assume each party_id appears exactly once in Parties and once in PartyLocations.
Define a party time block for a given (neighborhood, city, state) as a maximal continuous time interval during which there is at least one ongoing party in that neighborhood. If two party intervals in the same neighborhood overlap or touch (i.e., the end of one equals the start of another), they belong to the same block.
Task
Given the Parties and PartyLocations data, compute all party time blocks for each neighborhood.
Output
Return a list of records with the following fields:
neighborhoodcitystateblock_start_timestampblock_end_timestamp
Each record represents one maximal merged time block for that neighborhood. The list should be sorted by state, then city, then neighborhood, then block_start_timestamp.
You may assume there are up to (10^5) parties in total and should design an algorithm that is efficient for this input size.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.