Apple OA question | August 2022

Revision en1, by achyut.jagini, 2022-08-06 19:43:30

given — integer N number of nodes
2D array of size (N-1)*2
undirected graph

for each node determine number of paths containing node.
example for graph with edges 1-2 and 2-3

all paths — (1,2),(1,2,3),(2,3),(3,2),(3,2,1),(2,1)
node 1-4 times
node 2-6 times
node 3-4 times

so output is 4 6 4

Input format
1st line-no of testcases
2nd line -no of nodes(N)
next N lines 2 integers denoting source and destination vertex

Sample input
2
3
1 2
2 3
2
1 2

sample output
4 6 4
2 2

function
def count_paths(N,edges)

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English achyut.jagini 2022-08-06 20:21:47 40
en1 English achyut.jagini 2022-08-06 19:43:30 691 Initial revision (published)