Party Time by Town and Quiet Gaps by City
Problem statement
All parties occur during one day represented by integer minutes 0..1440.
Each string in parties has partyId start end for a half-open interval [start,end). Each string in geography has partyId town city state.
- For each town, union all of its party intervals and report total party minutes.
- For each city, union all party intervals and report every positive quiet gap between consecutive merged blocks. Do not include time before the city's first party or after its last party.
Return town lines first in town-name order as TOWN name minutes, then city lines in city-name order as CITY name gapStart-gapEnd,..., or NONE when there is no internal gap.
Function
summarizePartyTime(parties: String[], geography: String[]) → String[]Examples
Example 1
parties = ["p1 60 120","p2 100 180","p3 240 300"]geography = ["p1 North Metro CA","p2 North Metro CA","p3 South Metro CA"]return = ["TOWN North 120","TOWN South 60","CITY Metro 180-240"]North's overlapping parties merge to [60,180). Metro has one quiet gap before the South party.
Example 2
parties = ["a 0 30","b 30 60"]geography = ["a X C S","b X C S"]return = ["TOWN X 60","CITY C NONE"]Touching intervals form one continuous block.
Example 3
parties = ["a 10 20","b 40 50","c 0 5"]geography = ["a T1 C1 S","b T1 C1 S","c T2 C2 S"]return = ["TOWN T1 20","TOWN T2 5","CITY C1 20-40","CITY C2 NONE"]Outputs are grouped and sorted by geographic name.
Constraints
1 <= parties.length == geography.length <= 200000.- Party IDs are unique and appear once in each input.
0 <= start < end <= 1440.- Names contain no whitespace.