Race a Friend to a Shared Home
Updated
Problem statement
A friend starts at point F, you start at Y, and both race to the shared destination H. Each road takes the friend one minute and takes you pace minutes. Both choose a route with the fewest roads.
Each pair [a,b] in roads gives a road. For this exercise, assume the directed input selects the map convention: when true, the road goes only from a to b; when false, it can be used in either direction. All roads have equal hop cost for each traveler, regardless of their endpoints.
Return YOU WIN only if your arrival time is strictly smaller. Return FRIEND WINS if the friend arrives sooner or if the arrival times tie. A route from each starting point to H is guaranteed to exist.
Points are single characters. For this exercise, assume they are ASCII letters, names are case-sensitive, repeated roads have no additional effect, and a road connects two different points.
Function
raceHome(roads: String[][], pace: int, directed: boolean) → StringExamples
Example 1
roads = [["F","T"],["T","P"],["P","G"],["G","H"],["T","R"],["R","L"],["L","G"],["T","M"],["Y","M"],["M","N"],["N","H"]]pace = 1directed = falsereturn = "YOU WIN"The shortest friend route F → T → P → G → H uses four roads and takes four minutes. Your route Y → M → N → H uses three roads, so pace 1 gives three minutes and you win.
Example 2
roads = [["F","T"],["T","P"],["P","G"],["G","H"],["T","R"],["R","L"],["L","G"],["T","M"],["Y","M"],["M","N"],["N","H"]]pace = 2directed = falsereturn = "FRIEND WINS"The fewest-road distances are still four for the friend and three for you. At pace 2, your route takes six minutes, while the friend takes four, so the friend wins.
Constraints
- For this exercise, assume
2 <= roads.length <= 200and1 <= pace <= 100. - Every road has exactly two point labels, each a single ASCII letter.
- F, Y and H are distinct fixed role labels. Both F and Y can reach H under the selected directed or undirected convention.
- Cycles and repeated roads are allowed. There are no self-loops.
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
- Find Minimum City HopsAmazon · OA
- Fraud Ring SizeStripe · OAStripe interview questions
- Shortest Path from Encoded Graph EdgesBitGo · OABitGo interview questions
- Shortest Route Through a Traced MazeDuolingo · OADuolingo interview questions
- Word Chain Jumps in a GridGoogle · PHONE SCREENGoogle interview questions
- Hierarchical Permission CheckeBay · ONSITE INTERVIEWeBay interview questions
- Route Graph Reachability with a Broken LinkFigma · PHONE SCREENFigma interview questions
- Minimum Currency ConversionsEPAM · PHONE SCREENEPAM interview questions
- Finite Web CrawlerMongoDB · PHONE SCREEN · ONSITE INTERVIEWMongoDB interview questions
- Currency Conversion RateBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions