Mode: On-Campus Exam Pattern: 3 dsa questions OA Date: 2026-10-09
You are given an undirected tree consisting of N nodes numbered from 1 to N. A frog starts at node 1.
Every second, the frog jumps from its current node to an unvisited adjacent node. The frog cannot visit a previously visited node again.
https://leetcode.com/problems/frog-position-after-t-seconds/description/
If there are multiple unvisited adjacent nodes, the frog chooses one randomly, with equal probability for each available node.
If the frog has no unvisited adjacent nodes, it stays at its current node forever.
You are given an integer T representing the number of seconds and an integer target representing the target node.
Your task is to calculate the probability that the frog is at the target node after exactly T seconds.
Print the probability that the frog is at the target node after exactly T seconds.
Answers with an absolute error of at most 10^-5 are accepted.
7
1 2
1 3
1 7
2 4
2 6
3 5
2 4
0.1666666667
Initially, the frog is at node 1.
Therefore, the probability of reaching node 4 after exactly 2 seconds is:
Probability = (1/3) × (1/2) = 1/6 = 0.1666666667.
7
1 2
1 3
1 7
2 4
2 6
3 5
1 7
0.3333333333
After 1 second, the frog can move from node 1 to nodes 2, 3, or 7 with equal probability.
Therefore, the probability of being at node 7 after exactly 1 second is 1/3 = 0.3333333333.
Inmobi • 111 views
Inmobi • 101 views
Inmobi • 104 views
Inmobi • 566 views
Inmobi • 241 views