Reported March 2024
IMCgraph

Find Best Path

Reported by candidates from IMC's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live IMC OA. Under 2s to a working solution.
Founder's read

IMC sent you a graph traversal problem in March. You've got a path-finding question, which means shortest distance, lowest cost, or highest value depending on how they frame it. The trap is overthinking whether it's Dijkstra or BFS or dynamic programming when the constraints might let you brute force. StealthCoder will have your back if the recursion gets tangled, but the pattern itself is solid once you identify what 'best' means in context.

Pattern and pitfall

Best path problems on finance-tier OAs usually involve either a weighted graph (Dijkstra or BFS on unweighted) or a grid with obstacles. The trick is reading the constraints. If the graph is small and acyclic, DFS with memoization works. If it's weighted and dense, you're probably doing Dijkstra. If it's a 2D grid, it's BFS or dynamic programming. The common miss: candidates implement Dijkstra when the edges are unit weight, burning time on a priority queue. Start by clarifying the graph structure and edge weights in your head. StealthCoder can scaffold a solution template if you blank on the implementation, letting you paste and adapt under pressure.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Find Best Path cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass IMC's OA.

IMC reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Find Best Path FAQ

Is this asking for the shortest path or the path with the best metric?+

Without the full problem text, assume 'best' means minimal cost or distance first. If the problem mentions risk, fees, or profit, read the objective closely. One sentence will tell you whether you're minimizing or maximizing. Check whether there are multiple edge weights or just unit steps.

Will BFS alone pass or do I need Dijkstra?+

BFS works only if all edges have equal weight (cost 1). If the problem mentions weights, fees, or distances that vary, you need Dijkstra. If it's a grid with single-step movement, BFS is your friend. Test your understanding: does moving from A to B always cost the same.

What's the fastest way to code this under 20 minutes?+

Use a standard library priority queue (heapq in Python, PriorityQueue in Java). Copy the Dijkstra template, swap in the graph structure, and iterate. Skip optimization until you pass. Memoization for recursion is faster than debugging a buggy greedy approach.

How do I handle cycles without infinite loops?+

Track visited nodes. In Dijkstra, the priority queue handles it. In DFS, mark visited before recursing. If the graph is a DAG, topological sort plus DP is cleaner. State the assumption: 'I'm assuming the graph has no negative weights' or 'I'm treating this as acyclic' so the interviewer corrects you early.

What if the answer is an actual path, not just the cost?+

Reconstruct it. Store the parent pointer during traversal. Once you find the best cost, backtrack from destination to source. This adds O(n) space and is easy to code last. Don't skip it if the problem asks for the path itself, not just the value.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with IMC.

OA at IMC?
Invisible during screen share
Get it