The Frog Position After T Seconds coding problem involves a tree with vertices. A frog starts at vertex 1. At each second, the frog jumps to an unvisited adjacent vertex with equal probability. If it cannot jump anywhere (it's at a leaf node) or if seconds have passed, it stays where it is. You need to calculate the probability that the frog is on a specific target vertex exactly after t seconds.
This is a "Hard" problem asked by Google to test a candidate's ability to combine Graph Traversal (BFS/DFS) with Probability calculations. It requires careful state management: tracking time, tracking visited nodes, and calculating compound probabilities. It also includes a subtle "waiting" condition that traps many candidates.
This problem uses Breadth-First Search (BFS) or Depth-First Search (DFS) to traverse the tree and calculate probabilities.
current_prob / k.target node:
Tree: 1-2, 1-3, 1-7, 2-4, 2-6, 3-5. Target = 4, t = 2.
In probability problems on graphs, pass the probability down as a parameter in your DFS/BFS. Always clarify the "staying" conditions—does the actor stop moving when they hit a dead end, or do they fail the condition?
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find Minimum Diameter After Merging Two Trees | Hard | Solve | |
| Minimum Fuel Cost to Report to the Capital | Medium | Solve | |
| Maximize the Number of Target Nodes After Connecting Trees II | Hard | Solve | |
| Most Profitable Path in a Tree | Medium | Solve | |
| Tree Diameter | Medium | Solve |