The longest street in the world, MAX_STREET, is crossed by many other streets and driven by many drivers. Determine how many streets each driver crosses.
- A list (or array, depending on language) of streets that intersect MAX_STREET.
- A list (or array, depending on language) of drivers. Each driver is represented by a pair of streets. The first element of the pair is the street where they enter MAX_STREET; the second is the street they exit. The driver crosses all the streets between those two streets.
A list (or array, depending on language) showing how many streets each driver crosses.
count_streets(
["first", "second", "third", "fourth", "fifth", "sixth", "seventh"],
[("first", "second"), ("second", "seventh"), ("sixth", "fourth")]
)
should return [0,4,1]
.
- Each street name is a non-empty word of no more than 10 letters. There are no duplicate street names.
- The entry and exit streets for each driver are distinct. They are guaranteed to come from the list of streets.
- The number of streets
n
satisfies2 ≤ n ≤ 105
. The number of driversd
satisfies1 ≤ d ≤ 105.
So efficiency is important.