Microsoft Interview Question
1,272 Interview Reviews |
Back to all Microsoft Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Intern at Microsoft:
Given a tree find if any path that sums up to a given value the starting node may not be the root node always
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (2)
0 of 1 people found this helpful
we write a function which takes a node and then continues finding the desired path taking the provided node as the root oh the path(not the root of tree).
and we run this function for every node of tree.
time complexity O(n lgn)
Helpful Answer?
Yes |
No
Inappropriate?
To comment on this
question,
Sign In with Facebook or
Sign Up



0 of 0 people found this helpful
by Gerardo:
void SearchSum(Tree head, int sum, ArrayList<Integer> sol, int level)
{
if (head!=null)
{
sol.add(head.data);
int aux=0;
for(int i=sol.length;i>-1;i--)
{
aux+=sol[i];
if(aux==sum)
{
printArray(aux,i,level);
}
List<Integer> l1=sol.Clone();
List<Integer> l2=sol.Clone();
SearchSum(head.left, sum, sol, level+1);
SearchSum(head.right, sum,sol, level+1);
}
}
}
void printArray(ArrayList<Integer> aux,int i,int level)
{
String sol="";
for(int j=i;j<level;j++)
{
sol+=aux[j]+";";
}
Console.WriteLine(sol);
}