We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defgridlandMetro(n,m,k,track):bins=defaultdict(list)# match each track interval to its rowfort,s,eintrack:bins[t].append([s,e])# initially we have the whole grid availableans=m*nforbinbins.values():# sort the intervals by start time/positionb.sort()gap=0l_bound,r_bound=b[0]foriinrange(1,len(b)):# the intervals overlap - combine themifb[i][0]<=r_bound:l_bound=min(l_bound,b[i][0])r_bound=max(r_bound,b[i][1])# the intervals don't overlap - we need to remove space from the gridelse:gap+=r_bound-l_bound+1l_bound,r_bound=b[i]# the final interval won't be handled in the loopgap+=r_bound-l_bound+1ans-=gapreturnans
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Gridland Metro
You are viewing a single comment's thread. Return to all comments →