putta.sreenivas
BAN USER- 1of 1 vote
AnswersConsider a series in which 8 teams are participating. each team plays twice with all other teams. 4 of them will go to the semi final.How many matches should a team win, so that it will ensure that it will go to semi finals.?
- putta.sreenivas| Report Duplicate | Flag | PURGE
Amazon Google Developer Program Engineer Software Engineer / Developer Algorithm Brain Teasers - 0of 0 votes
AnswersGiven a set of numbers eg:{2,3,6,7,8} . any one who is playing the game can score points only from this set using the numbers in that set. given a number, print all the possible ways of scoring that many points. Repetition of combinations are not allowed.
- putta.sreenivas
eg:
1. 6 points can be scored as
6
3+3
2+2+2
2. 7 can be scored as
7
2+2+3
but 2+3+2 and 3+2+2 is not allowed as they are repetitions of 2+2+3| Report Duplicate | Flag | PURGE
Amazon Developer Program Engineer Algorithm
this code does not require parent pointer>>>>
public Tree commonAncestor(Tree root, Tree p, Tree q) {
if (covers(root.left, p) && covers(root.left, q))
return commonAncestor(root.left, p, q);
if (covers(root.right, p) && covers(root.right, q))
return commonAncestor(root.right, p, q);
return root;
}
private boolean covers(Tree root, Tree p) { /* is p a child of root? */
if (root == null) return false;
if (root == p) return true;
return covers(root.left, p) || covers(root.right, p);
}
good approach
- putta.sreenivas May 12, 2011no, its 11. see the above comment.
- putta.sreenivas May 11, 2011there is a good logic through which you can eliminate all other horses except remaining best 5 , within three other races..
- putta.sreenivas May 11, 2011total no. of games can be played are: (8c2)*2. that is 56.so, 56 points can be scored overall if for one win one point is considered. consider one team losses all matches . second team wins 2 matches and 3rd team wins 4 matches. now totally 6 points are csored. now 50 points left for 5 teams. consider remaining five teams score 10 points each. even in that case also tie may happen for all 5 teams. so, you need to score 11 points to be in semi final.
- putta.sreenivas May 11, 2011but still as you said answer is 11 only, but in other way.. think the other possible way?
- putta.sreenivas May 11, 2011but wen you said A,B,C,D won all matches with E,F,G,H. they will have 8 points.now the maximum points that E,F,G,H can score at this situation is 6 only. so, irrespective of no. of points A,B,C,D score they will be definitely more than E,F,G,H. so by that time itself A,B,C,D will be in semis.
- putta.sreenivas May 11, 2011No, The answer is definitely 12. So, think for getting answer as 12.
- putta.sreenivas May 11, 2011when best team wins 14 points, it has won all the games right? that means with the second best team it has won all 2 games. then second best team definitely losses two matches. then how come it can score 13 points.? it can score only 12 points.
- putta.sreenivas May 11, 2011is there any openings right now in adobe? if yes is it for freshers or experienced. how to apply? please help me?
- putta.sreenivas May 10, 2011let me explain:
step1:divide 81 into 9 groups
group1:a1,a2,a3,......a9
group2:b1,b2,........b9
......................
......................
group9:i1,i2,i3,......i9
step 2:now conduct race for each group. you will get best in each group. so totally 9 races conducted.
step3:let the best ones be a1,b1,c1,d1,e1,f1,g1,h1,i1.
now conduct a race for all of them. i.e., 10th race. take the 6 good ones among them.
let the best ones be a1,b1,c1,d1,e1,f1. now no need to consider 'g' , 'h', 'i series 'as the best ones among those series even can't make a place in top 6.
step 4:
so, 1st best is a1.
now we will see what are the possibilities for remaining positions.
2nd : a2,b1
3rd : a2,a3,b1,b2,c1
4th : a2,a3,a4,b1,b2,b3,c1,c2,d1
5th : a2,a3,a4,a5,b1,b2,b3,b4,c1,c2,c3,d1,d2,e1
6th : a2,a3,a4,a5,a6,b1,b2,b3,b4,b5,c1,c2,c3,c4,d1,d2,d3,e1,e2,f1
step 4:
now we will try to find out second best, third best, fourth best.
liable candidates for these postions are
2nd : a2,b1
3rd : a2,a3,b1,b2,c1
4th : a2,a3,a4,b1,b2,b3,c1,c2,d1.
take common things by eliminating repeated ones
a2,a3,a4,b1,b2,b3,c1,c2,d1.totally 9 are there. conduct a race for these 9. you will get 2nd, 3rd, 4th ones.
step 6:
from the set 5th one came, there is possibility that sixth one can be in the set. from that 2 horses we will take.from the set 6th one came, we will take only the sixth one. so, totally we are taking 3 horses. we will take e1,e2,f1 as they are liable for 5th and 6th position. now totally 6 horses we made for next race.from which the 7th, 8th, 9th came . we can eliminate those sets.at minimum we can eliminate one set from consideration. i.e., 'a' set because it is only the set from which three horses participated.so, from the remaining three sets we can select three horse. so totally 9 horses. conduct 12th race among them to determine the 5th and 6th best..
Answer is 12.
- putta.sreenivas May 10, 2011Sorry the answer is 12.
- putta.sreenivas May 10, 2011sorry. each time 9 races can participate in the race..
- putta.sreenivas May 10, 2011no, i did the above problem with some bugs. i was rejected. and i attended in India
- putta.sreenivas May 10, 2011Can you explain it in proper way with an example.. the solution seems to be confusing.., and not getting what you are doing?
- putta.sreenivas May 10, 2011sorry, it won't work.when you r comparing A[i], A[j] if A[i]>A[j] then you are moving both i and j.in that case it may happen like A[i+1]>A[j-1] but there may be possibility that A[i+1]<A[j] or A[i]<A[j-1] .In both of these cases the difference in indexes is j-(i+1) and (j-1)-i. that means j-i-1 which is bigger than (j-1)-(i+1). that is j-i-2.
- putta.sreenivas May 09, 2011that is of too much running time... and also repetitions will come... I don't know the exact solution ,but what we can do is , we should sort the arry. then we can discard all the numbers above the required number.. now with the subset we got , we should proceed.. don't know how to approach later...and definitely it can be solved in better time..
- putta.sreenivas May 09, 2011Insert head into queue.
now run a loop until the queue is empty. inside the loop
1.dequeue the front of the queue. if it is equal to our data, print it and return.
else
2.Use a function called getchildnodes(node *head) to get all the childs of a particular node.
3. enquue all these child nodes into the queue.
4. repeat the process until queue becomes empty.
hey, where did you attend interview with adobe. ? when did you attend? is there any openings now in adobe in india?
- putta.sreenivas May 13, 2011