You are given two datasets:
party_id
(string or integer)
start_timestamp
(e.g., UNIX timestamp or datetime)
end_timestamp
(same type as
start_timestamp
, and
end_timestamp > start_timestamp
)
party_id
neighborhood
(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:
neighborhood
city
state
block_start_timestamp
block_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 parties in total and should design an algorithm that is efficient for this input size.