Reachable Nodes In Subdivided Graph
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You start with an undirected graph of n nodes labeled 0 to n - 1. Each entry edges[i] = [u, v, cnt] describes an edge between u and v that has been **subdivided** by inserting cnt brand-new nodes along it, turning the single edge into a path of cnt + 1 edges. (cnt = 0 leaves the edge as-is.)
Starting at node 0, every step moves along one edge of this new, subdivided graph. A node is **reachable** if it can be reached in at most maxMoves steps.
Return the number of reachable nodes in the subdivided graph, counting both original nodes and inserted nodes. There are no self-loops and no duplicate edges between the same pair of original nodes; some original nodes may be disconnected from 0.
Examples
Constraints
- 0 <= edges.length <= min(n * (n - 1) / 2, 10^4)
- edges[i] = [u, v, cnt] with 0 <= u < v < n
- 0 <= cnt <= 10^4
- 0 <= maxMoves <= 10^9
- 1 <= n <= 3000
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.