Shipping Starts and Terminal Destinations
Updated
Problem statement
Autonomous delivery carts move packages along one-way routes. Each pair [from,to] in routes gives one directed step between uniquely named locations. The directed graph has no cycles.
Find every starting location, meaning a represented location with no incoming route. For each start, find every terminal destination reachable by one or more routes. A terminal destination has no outgoing route. Branching, merging, and separate components are allowed.
Return one row [start, destination1, destination2, ...] for each start. Sort the rows by their start names and sort each row's destinations. For this exercise, assume sorting uses case-sensitive ASCII order, every location is represented by a pair endpoint, and repeated routes or multiple paths to a destination contribute only one destination. Return an empty array for no routes.
Function
shippingDestinations(routes: String[][]) → String[][]Examples
Example 1
routes = [["A","B"],["A","C"],["B","K"],["C","K"],["E","L"],["F","G"],["J","M"],["E","F"],["G","H"],["G","I"]]return = [["A","K"],["E","H","I","L"],["J","M"]]The two branches from A both end at K, which appears once. From E, the direct branch ends at L and the branch through F and G ends at H or I. J reaches only M. Starts and destinations are sorted.
Example 2
routes = [["B","C"],["A","C"],["C","D"],["C","E"]]return = [["A","D","E"],["B","D","E"]]A and B are both starts. Their paths merge at C, then split to terminal destinations D and E, so both rows contain both destinations.
Constraints
- For this exercise, assume
0 <= routes.length <= 60. - Every route has exactly two different location names. Each name has 1 to 30 printable ASCII characters and contains a non-space character.
- The directed graph is acyclic. Repeated copies of a route are allowed.
More Intuit Online Assessment questions
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026
- Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
- Maximum Square-Free DivisorOA · Seen Oct 2026
- Two Tribes from Taller-Person CountsOA · Seen Oct 2026
- Shortest Path from an Encoded GraphOA · Seen Sep 2026
- Oldest and Youngest EmployeesOA · Seen Sep 2026
- Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
- Submask Sum QueriesOA · Seen Sep 2026
Similar questions at other companies
- Platform Referral RewardsScale AI · OAScale AI interview questions
- Module Rebuild CostsAirbnb · OAAirbnb interview questions
- Maximum Reservoir PowerWells Fargo · OAWells Fargo interview questions
- Minimum Leaf Path Sum over All RootsInfosys · OAInfosys interview questions
- Evolving Merchant Clusters and Persistent PinsStripe · OAStripe interview questions
- Maximum Strength of Every NeuronMicrosoft · OAMicrosoft interview questions
- Create Lexicographically Largest PermutationOracle · OAOracle interview questions
- Tree Node With Maximum BeautyC3.ai · OAC3.ai interview questions
- Longest Increasing Path in a MatrixNutanix · OANutanix interview questions
- All Halfway Courses Across Course TracksCrunchyroll · PHONE SCREENCrunchyroll interview questions