Minimum Cost of a Path With Special Roads
A medium-tier problem at 40% community acceptance, tagged with Array, Graph, Heap (Priority Queue). Reported in interviews at Samsung and 0 others.
You're staring at a path problem with special roads, and it feels like a shortest-path variant until you realize the trap. Most candidates try classic Dijkstra and miss the state design entirely. Samsung has asked this one, and it's the kind of problem where the obvious graph setup fails silently. The trick isn't the algorithm, it's modeling what a 'state' actually is. If you hit this in your OA and freeze on the state representation, StealthCoder surfaces a working solution in seconds, invisible to the proctor.
Companies that ask "Minimum Cost of a Path With Special Roads"
Minimum Cost of a Path With Special Roads is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop.
Get StealthCoderThis problem wraps Dijkstra or priority-queue shortest-path logic, but the difficulty spike comes from recognizing that you're not just tracking 'visited nodes'. Each position can be reached with different costs, and the special roads create a non-standard graph where the state must encode position and sometimes intermediate choices. Many candidates build a standard shortest-path tree and get TLE or Wrong Answer because they didn't account for revisiting nodes at lower costs. The heap-based approach is solid once you nail the state, but getting there requires a mental shift from 'visit each node once' to 'process each (position, cost) pair'. When the pattern clicks during prep, you're set. When it doesn't, and you're live in an OA, StealthCoder's solution logic cuts through the confusion.
Pattern tags
You know the problem.
Make sure you actually pass it.
Minimum Cost of a Path With Special Roads recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum Cost of a Path With Special Roads interview FAQ
Is this really a Dijkstra problem or something trickier?+
It's Dijkstra, but the state design is the hard part. You can't just mark nodes visited; you need to track cost per position and allow revisits if the cost is lower. The heap ensures you process cheaper paths first, so the algorithm is sound once the state is right.
What's the acceptance rate telling me about difficulty?+
40% acceptance is solid for Medium. It's not a rare edge-case problem, it's a pattern recognition miss. Most people who understand shortest-path and heap mechanics will solve it. The bar is understanding when to revisit a node, not inventing a new algorithm.
Samsung asked this. Should I expect it at other big tech companies?+
One company in the data set asked it, so no broad FAANG signal. But the pattern, it appears across shortest-path problems everywhere. Master the state design here and you own similar problems at any company.
What's the gotcha that tanks people in the OA?+
Forgetting that special roads can make backtracking or detours cheaper than the direct route. Your state needs to allow revisiting positions. If you lock nodes as visited too early, you'll miss the optimal path and time out or return the wrong answer.
How do I prep this if I keep getting WA on test cases?+
Print or trace your heap pops and the cost updates for each position. Watch for cases where you reach the same position twice at different costs. If your code ignores the second arrival, that's your bug. The test cases probably include a detour that's actually cheaper.
Want the actual problem statement? View "Minimum Cost of a Path With Special Roads" on LeetCode →