7 kyu

How Many Streets?

256 of 478brodiemark

Description:

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.

Inputs

(1) A list (or array, depending on language) of streets that intersect MAX_STREET. (2) 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.

Output

A list (or array, depending on language) showing how many streets each driver crosses.

Example

count_streets(["first", "second", "third", "fourth", "fifth", "sixth", "seventh"], [("first", "second"), ("second", "seventh"), ("sixth", "fourth")]) should return [0,4,1].

Details:

(1) Each street name is a non-empty word of no more than 10 letters. There are no duplicate street names.

(2) The entry and exit streets for each driver are distinct. They are guaranteed to come from the list of streets.

(3) The number of streets n satisfies 2 ≤ n ≤ 105. The number of drivers d satisfies 1 ≤ d ≤ 105. So efficiency is important.

Source: International Collegiate Programming Contest, North Central North American Regional, 2022.

Arrays
Searching
Performance

More By Author:

Check out these other kata created by brodiemark

Stats:

CreatedOct 2, 2024
PublishedOct 5, 2024
Warriors Trained1208
Total Skips33
Total Code Submissions800
Total Times Completed478
Python Completions256
Java Completions134
C# Completions53
Kotlin Completions21
Swift Completions33
Lua Completions6
Total Stars17
% of votes with a positive feedback rating83% of 80
Total "Very Satisfied" Votes59
Total "Somewhat Satisfied" Votes14
Total "Not Satisfied" Votes7
Total Rank Assessments13
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • brodiemark Avatar
  • hobovsky Avatar
  • dfhwze Avatar
  • metatable Avatar
Ad