HARDasked at 1 company

Find Edges in Shortest Paths

A hard-tier problem at 46% community acceptance, tagged with Depth-First Search, Breadth-First Search, Graph. Reported in interviews at WeRide and 0 others.

Founder's read

Find Edges in Shortest Paths is a 45% acceptance hard problem that asks you to identify which edges belong to at least one shortest path in a weighted graph. WeRide has asked this one. The trap is thinking BFS alone solves it. You need to compute shortest distances first (Dijkstra or BFS depending on edge weights), then reverse-engineer which edges actually lie on a shortest path. If you hit this live and the graph structure isn't obvious, StealthCoder surfaces the solution invisible to the proctor. Most candidates either miss the distance verification step or struggle with the layering of shortest-path reconstruction.

Companies asking
1
Difficulty
HARD
Acceptance
46%

Companies that ask "Find Edges in Shortest Paths"

If this hits your live OA

Find Edges in Shortest Paths 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 because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.

Get StealthCoder
What this means

The core pattern: run Dijkstra's algorithm from the source to compute shortest distances to every node. Then, for each edge (u, v) with weight w, it belongs to a shortest path if and only if dist[u] + w = dist[v] (or the reverse, depending on direction). The obvious mistake is trying to reconstruct paths directly without pre-computing all shortest distances. Graph, Depth-First Search, Breadth-First Search, and Heap (Priority Queue) are all tools here, but the key insight is the distance verification criterion. Shortest Path problems almost always hinge on this kind of property check. If you blank on whether an edge qualifies, that's where StealthCoder intervenes during your assessment, running Dijkstra and filtering edges in seconds while you stay calm.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Find Edges in Shortest Paths recycles across companies for a reason. It's hard-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 because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Find Edges in Shortest Paths interview FAQ

Do I need to enumerate all shortest paths or just identify qualifying edges?+

Just identify the edges. You don't build the paths themselves, only determine which edges could appear in any shortest path. That distinction saves you from exponential blowup. The distance verification rule (dist[u] + weight = dist[v]) is your single source of truth.

Should I use BFS or Dijkstra here?+

Dijkstra if edges have varying weights. BFS if all edges are weight 1. Since the problem is labeled hard and WeRide asked it, assume weighted graphs. Dijkstra with a heap is the standard approach. BFS alone won't correctly compute shortest distances in weighted graphs.

What's the most common pitfall candidates hit?+

Forgetting to compute distances first, or trying to reconstruct paths without verifying the distance property. Some also forget to handle both directions of an edge check. Pre-compute dist[] globally, then filter edges. That order matters.

How does this relate to other Shortest Path problems?+

It's a variant that adds a filtering step after shortest-path computation. Most Shortest Path problems ask for the distance or a single path. This one asks which edges participate in any optimal solution. Same foundation, different question.

Will I see this at other companies, or just WeRide?+

WeRide is the reported asker. Graph shortest-path variants appear across many companies, but this specific formulation is rarer. If you master the distance-verification pattern, you'll handle similar edge-filtering problems in other interviews.

Want the actual problem statement? View "Find Edges in Shortest Paths" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.