How Many Streets?
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.
Similar Kata:
Stats:
Created | Oct 2, 2024 |
Published | Oct 5, 2024 |
Warriors Trained | 1208 |
Total Skips | 33 |
Total Code Submissions | 800 |
Total Times Completed | 478 |
Python Completions | 256 |
Java Completions | 134 |
C# Completions | 53 |
Kotlin Completions | 21 |
Swift Completions | 33 |
Lua Completions | 6 |
Total Stars | 17 |
% of votes with a positive feedback rating | 83% of 80 |
Total "Very Satisfied" Votes | 59 |
Total "Somewhat Satisfied" Votes | 14 |
Total "Not Satisfied" Votes | 7 |
Total Rank Assessments | 13 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 7 kyu |
Lowest Assessed Rank | 7 kyu |