You are given two in-memory datasets for a party-planning app.
-
PartyWindow: {partyId: string, startTime: ISO-8601 UTC datetime, endTime: ISO-8601 UTC datetime} with startTime < endTime.
-
GeoData: {partyId: string, state: string, county: string, town: string, community: string}. Each partyId appears exactly once in each dataset. Implement:
(a) A method that joins PartyWindow with GeoData on partyId and returns, for every community, the earliest party start and the latest party end across all parties in that community. Specify your return type (e.g., Map<community, [minStart, maxEnd]>) and how you handle sorting/output order.
(b) A method that, using the same inputs, computes for every town the total number of hours during which no party is happening anywhere in that town. First, within each town, merge overlapping or adjacent intervals (adjacent means end == nextStart and should not count as a gap). Then sum the durations of gaps strictly between the merged intervals over the span from the earliest start to the latest end observed in that town. Return Map<town, hours>, using UTC and ignoring DST, and state any rounding policy. State and justify the time and space complexity of your solutions, and discuss data structures you would use (e.g., hash maps, sorting, interval merging).