Streets Ahead
InterviewTime limit2sMemory limit1024 MB
Given street names in road order, answer each query with the number of intersections from the start street to the end street, inclusive.
- Level
Easy3 of 10
- Topics
- Hash map, Implementation
- Solved
- No attempts yet
Problem
International Connecting Passage Causeway is a long, rutted two-way country road crossed by streets at different points.
There are many drivers, and each will drive along the country road starting at some intersection and ending at some other intersection. For each driver, how many intersections will they drive through?
Input
The first line contains two integers, and , where is the number of cross streets and is the number of drivers.
Each of the next lines contains a string of at most ten lowercase letters representing the name of one of the streets that crosses the country road. All street names are unique. Driving along the country road in some direction, one sees these streets in exactly the order provided.
Each of the next lines contains two strings of at most ten lowercase letters representing the start and end intersection for each driver. Queries will be between distinct streets.
Output
Output lines, the th line containing the number of intersections that the th driver drives through.