As reported: Snap MLE coding interview (2025), question 2: a random walk on an undirected tree from vertex 1 — no revisiting, equal chances among the possible next vertices, a dummy step that stays put when no move is possible; return the probability of being at vertex
kafterssteps.
This is LeetCode 1377 — Frog Position After T Seconds (t = the number of steps, target = the vertex).
An undirected tree has n vertices numbered 1 … n; edges[i] = [a, b] is an edge. A walker starts at vertex 1. Every second it moves to one of the unvisited neighbours of its current vertex, each with equal probability. If there is no unvisited neighbour, it stays where it is forever.
Return the probability that the walker is on vertex target after t seconds.
Example 1
n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 2, target = 4
Output: 0.16667
1 → 2 with probability 1/3, then 2 → 4 with probability 1/2: 1/6.
Example 2
n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 1, target = 7
Output: 0.33333
Constraints: 1 ≤ n ≤ 100; edges.length = n − 1; 1 ≤ t ≤ 50; 1 ≤ target ≤ n. Answers within 10^-5 of the true value are accepted.
Code runner format: one JSON value per line: n, edges, t, target. Implement frogPosition(n, edges, t, target); the harness prints the probability with 5 decimals.