Leetcode 2662. Minimum Cost of a Path With Special Roads
Find the minimum cost to go from start to target in a 2D grid where moving anywhere costs Manhattan distance but there are directed "special roads" (fixed-cost shortcuts between given points, reusable) that may reduce cost. Model start, target and all road endpoints as graph nodes with edges for Manhattan distances and directed special-road edges, then compute the shortest path (e.g., Dijkstra).
Asked at:
Goldman Sachs
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Early March, 2026
Goldman Sachs
Mid-level
# ** Instructions to candidate. # ** 1) You are an avid rock collector who lives in southern California. Some rare # ** and desirable rocks just became available in New York, so you are planning # ** a cross-country road trip. There are several other rare rocks that you could # ** pick up along the way. # ** # ** You have been given a grid filled with numbers, representing the number of # ** rare rocks available in various cities across the country. Your objective # ** is to find the optimal path from So_Cal to New_York that would allow you to # ** accumulate the most rocks along the way. # ** # ** Note: You can only travel either north (up) or east (right). # ** 2) Consider adding some additional tests in doTestsPass(). # ** 3) Implement optimalPath() correctly. # ** 4) Here is an example: # ** ^ # ** {{0,0,0,0,5}, New_York (finish) N # ** {0,1,1,1,0}, < W E > # ** So_Cal (start) {2,0,0,0,0}} S # ** v # ** The total for this example would be 10 (2+0+1+1+1+0+5).
Late September, 2024
Mid-level
BFS problem: Find minimum cost path from source to destination with least roads taken, given equal cost roads
Hello Interview Premium
Your account is free and you can post anonymously if you choose.