Re: [algogeeks] What would be the output of the following program..?
answer will be -1 because the statement in while loop will never executed as (+(+0)!=0) this will be evaluated as false because zero is not equal to zero and i is decremented in here but decrementation is postfix uses the value first and decrement it after sequence point which is the condition point of while loop and hence the answer is -1 On Mon, Dec 13, 2010 at 8:15 PM, siva viknesh sivavikne...@gmail.comwrote: int main() { int i=0; while(+(+i--)!=0) i-=i++; printf(%d\n,i); return 0; } (a) -1 (b) 1 (c) -65535 (d) 0 Ans is option 'a' .. but how?? anybody help plz? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: matrix sum
O(nm) preprocessing is required. A[i][j] contains sum of all numbers which lies into a rectangle with bottom right corner at (i, j). To answer the query: decompose rectangles and find the answer via some addition and subtractions. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: C aps ques
for 2nd problem: statement inside the do-while is executed once. Now for the condition checking inside the while loop. The condition i++5 is evaluated which turns out to be true. So the rest of the part ++ch='F' is not evaluated and hence letter A is printed six times. Now when the condition i++5 fails, then the condition ++ch='F' would be evaluated which prints BCDEF. This is a property of the logical OR. If the first condition evaluates to true, then rest of the condition is not evaluated as it would always turn out to be true. However, if the first condition is false then only the second condition is checked to get the final output. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: C aps ques
correct me if I am wrong. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: C aps ques
Exactly!! On 12/14/10, RAHUL KUJUR kujurismonu2...@gmail.com wrote: correct me if I am wrong. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: matrix sum
question is based on simple D.P. use an auxiliary matrix to record the sum of all rectangles we are possible and use this matrix in subsequent quering there is an example 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 this is our original matrix now keep on doing the sum on auxiliary matrix aux[i][j]=aux[i-1][j]+aux[i][j-1]+original[i][j] this is the relation . hope this helps correct me if i m wrong. On Tue, Dec 14, 2010 at 2:52 PM, juver++ avpostni...@gmail.com wrote: O(nm) preprocessing is required. A[i][j] contains sum of all numbers which lies into a rectangle with bottom right corner at (i, j). To answer the query: decompose rectangles and find the answer via some addition and subtractions. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Google interview question
i have a one idea in my mind is to implement a hash table structure based on 26 alphabets and a data structure of words. struct word { int info; char a[n]; }; structure contains the info about the word and an array in which document it is present or not out of n ex if it is word is mnnit and it is in document 1 ,4,6,9 the info of the structure would be char[1,4,6,9]=1 and the rest are zero. insertion of word would take o(1) time but searching would take o(n) time if list is implemented as an array list and if implemented as an binary search tree would take it log(n) but than insertion would also take log(n) time On Mon, Dec 13, 2010 at 9:55 PM, GOBIND KUMAR gobind@gmail.com wrote: One of my friends attended google interview.This was one the question asked. you are given N documents(possibly in millions) with words in them. design datastructures such that the following scenarios take optimal time: a. print all the the docs having a given word b. print the docs having both of 2 given words Help me in solving this problem. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: The best multiply matrix algorithms ?
That's OK Mr. Rakib! :) But, how can a computer make faster this computation using parallel programming ? Can one real programming language's rotine make use this aproach giving to a sub-rotines concurrents tasks ? We make a change this question: what the computer's architecture that's make a faster multiplying matrixes using a parallel programming ? 2010/12/12 Rakib Ansary Saikot ansaryfantas...@gmail.com: It is NOT possible to multiply two matrices in less than O(n^2) simply because there are n^2 elements, and you got to touch all of them at least once! Rakib -- Luciano. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Google interview question
According to me, the problem is regarding fastest search of substrings.. Hashing is one of the solutions. Use Rabin-Karp Search.. Use wiki at: http://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_string_search_algorithm#Rabin.E2.80.93Karp_and_multiple_pattern_search On Dec 14, 4:01 pm, sourabh jakhar sourabhjak...@gmail.com wrote: i have a one idea in my mind is to implement a hash table structure based on 26 alphabets and a data structure of words. struct word { int info; char a[n];}; structure contains the info about the word and an array in which document it is present or not out of n ex if it is word is mnnit and it is in document 1 ,4,6,9 the info of the structure would be char[1,4,6,9]=1 and the rest are zero. insertion of word would take o(1) time but searching would take o(n) time if list is implemented as an array list and if implemented as an binary search tree would take it log(n) but than insertion would also take log(n) time On Mon, Dec 13, 2010 at 9:55 PM, GOBIND KUMAR gobind@gmail.com wrote: One of my friends attended google interview.This was one the question asked. you are given N documents(possibly in millions) with words in them. design datastructures such that the following scenarios take optimal time: a. print all the the docs having a given word b. print the docs having both of 2 given words Help me in solving this problem. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: What would be the output of the following program..?
but how comma is evaluated and the value assigned to variable 'c' is the expression evaluated on the RHS of commais there any such rules in C ?? generally for comma separated value the compiler ignores all values to the right of first comma. eg. in above case c=--a,b++ - c; the compiler just evaluates the values after first comma(b++ - c) but uses only c = --a for assignment purpose. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: What would be the output of the following program..?
the rule governs that in exprns on both the side gets evaluated only if first exprns gives TRUE if 1st one gives FALSE then whatever be 2nd exprn answer be FALSE and in || 2nd side is not evaluated if 1st side replies with TRUE.. On Dec 13, 9:10 pm, siva viknesh sivavikne...@gmail.com wrote: int main() { int k = 5; if (++k 5 k++/5 || ++k = 8); printf(%d\n, k); return 0; } for the above code output is '7' and not '8'...why?? int main() { int k = 5; if (++k 5 k++/5 ); printf(%d\n, k); return 0; } similarly for the above code output is '6' and not '7'...why?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: What would be the output of the following program..?
ya all the exprn is evaluated and left expr is assigned .. On Dec 13, 9:21 pm, siva viknesh sivavikne...@gmail.com wrote: #includestdio.h int main() { int a=1,b=2,c=3; c=--a,b++ - c; printf(%d %d %d,a,b,c); return 0; } the above code is perfectly valid and prints 0 3 0 ... but how comma is evaluated and the value assigned to variable 'c' is the expression evaluated on the RHS of commais there any such rules in C ?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: matrix sum
After making the aux array (as written in above post), you can answer any query in O(1) time by using the following relation: assuming top left as (x1,y1) and bottom right as (x2,y2) sum_of_rectangle = aux[x2][y2] - aux[x1-1][y2] - aux[x2][y1-1] + aux[x1-1][y1-1] It may happen that while subtracting 1 from any variable above the value may come out to be negative. That should be handled. Regards. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] file handling
programs for basic operation. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] C aps ques
the evalution will be done from right to left in printf statement..so ++x will be evaluted and then x++.may be the out put is 6 and 6 i think On 13 December 2010 22:39, siva viknesh sivavikne...@gmail.com wrote: #includestdio.h int main() { int x = 5; printf(%d %d, x++, ++x); return 0; } for this output is 6 7 ... how evaluation proceeds?? -- Regards, $iva -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: What would be the output of the following program..?
thanks a lot for your explanation:) On Dec 14, 2:48 pm, sourabh jakhar sourabhjak...@gmail.com wrote: answer will be -1 because the statement in while loop will never executed as (+(+0)!=0) this will be evaluated as false because zero is not equal to zero and i is decremented in here but decrementation is postfix uses the value first and decrement it after sequence point which is the condition point of while loop and hence the answer is -1 On Mon, Dec 13, 2010 at 8:15 PM, siva viknesh sivavikne...@gmail.comwrote: int main() { int i=0; while(+(+i--)!=0) i-=i++; printf(%d\n,i); return 0; } (a) -1 (b) 1 (c) -65535 (d) 0 Ans is option 'a' .. but how?? anybody help plz? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] how many bananas?
There is a desert of 1000kms long. A camel is there and 3000 bananas. At one go a camel can take 1000 bananas. For each one km to walk camel eats 1 banana. How many bananas can we cross to the other side of desert -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] array
an array contain +ve and -ve element, find subarray whose sum =0; Lets take input array as a[]={-3,2,4,-6,-8,10,11} -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Amazon Interview Question
given some positive numbers output the numbers in decreasing order of frequency..in case of a tie print the number which occurred first for eg: 1,3,3,1,2,3,5,2,3 the output should be 11225 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: how many bananas?
total bananas=3000 ...max capacity=1000 ==3 trips needed to transport all for traveling 1 km 1st trip 998[eats 1 banana while coming and 1 banana while going back] 2nd trip 998 3rd trip 999[no need to go back] ==5 banana for travelling 1 km since 3 trips involved v spend 5 banana per km v need to reduce it to 2 trips ==the point where total banana becomes 2000 ==3000-2000=1000 ==1000/5=200 km at 200 km v hav 2000 bananas now for travelling 1 km 1st trip 998 2nd trip 999 ==3 banana for travellin 1 km find the point where this becomes single trip dat is total banana becomes 1000 ==2000-1000=1000 ==1000/3=333.3km v hav reached 533.33 km with 1000 banana now make a single trip of remaining 466.66 to city B v reach city B with 533.3 banana dats the answer 533 1/3 banana On Dec 14, 5:47 pm, divya sweetdivya@gmail.com wrote: There is a desert of 1000kms long. A camel is there and 3000 bananas. At one go a camel can take 1000 bananas. For each one km to walk camel eats 1 banana. How many bananas can we cross to the other side of desert -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] linkd list
Given three lists: A, B and C of length n each. Write a function which returns true if any 3 three numbers (1 from each list), sum up to zero. Else return false, if there is no such combination. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] matrix sum
with an O(nm) preprocessing the queries will take O(1) for each cell x,y find sum[x,y] which is sum of all elements in rectangle with coordinates (0,0) (x,y) . this can be done in O(nm) (using inclusion-exclusion principle) sum[x,y] = a[x,y] + sum[x-1,y] + sum[x,y-1] - sum[x-1,y-1] now for each query (x1,y1) (x2,y2) the result is sum[x2, y2] - sum[x1-1, y2] - sum[x2, y1-1] + sum[x1-1, y1-1] -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Spoj- the next palindrome
hi, i was doing this problem : http://www.spoj.pl/problems/PALIN/ and i dont know why my solution was not giving AC . i have applied a simple strategy.if no. of digits are even , then mirror the first half and then add it to the first half. we get the plaindrome.if it is same as the given no. then just increment the first half and mirror it and add it to the first half again.Now also , the digits can be like this or 99 .I have made sure to treat this as a special case and my output for these is 10001 and 101 . I have applied a similar strategy for odd no of digits by increasing the middle elemnt and amirroring the first half around the middle element. here is the link to my solution http://paste.ubuntu.com/543644/ I would appreciate if anybody could help me here. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Spoj- the next palindrome
the question exactly was to find next palindrome just greater than the given no. The number could have a million digits. On Tue, Dec 14, 2010 at 9:01 PM, Ankur ankur.kkhur...@gmail.com wrote: hi, i was doing this problem : http://www.spoj.pl/problems/PALIN/ and i dont know why my solution was not giving AC . i have applied a simple strategy.if no. of digits are even , then mirror the first half and then add it to the first half. we get the plaindrome.if it is same as the given no. then just increment the first half and mirror it and add it to the first half again.Now also , the digits can be like this or 99 .I have made sure to treat this as a special case and my output for these is 10001 and 101 . I have applied a similar strategy for odd no of digits by increasing the middle elemnt and amirroring the first half around the middle element. here is the link to my solution http://paste.ubuntu.com/543644/ I would appreciate if anybody could help me here. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] subarraysum
Given an array of integers your task is to find the subarray with the sum 0. Using same approach find the subarray with a sum k. Find the solution in linear time and constant space. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] largest substring
Given a string, find the largest substring that occur multiple times within the same string. Extend your code to find the substring occuring atleast n times. Perform in linear time and space. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: how many bananas?
nice solution:) On 14 December 2010 20:54, Prims topcode...@gmail.com wrote: total bananas=3000 ...max capacity=1000 ==3 trips needed to transport all for traveling 1 km 1st trip 998[eats 1 banana while coming and 1 banana while going back] 2nd trip 998 3rd trip 999[no need to go back] ==5 banana for travelling 1 km since 3 trips involved v spend 5 banana per km v need to reduce it to 2 trips ==the point where total banana becomes 2000 ==3000-2000=1000 ==1000/5=200 km at 200 km v hav 2000 bananas now for travelling 1 km 1st trip 998 2nd trip 999 ==3 banana for travellin 1 km find the point where this becomes single trip dat is total banana becomes 1000 ==2000-1000=1000 ==1000/3=333.3km v hav reached 533.33 km with 1000 banana now make a single trip of remaining 466.66 to city B v reach city B with 533.3 banana dats the answer 533 1/3 banana On Dec 14, 5:47 pm, divya sweetdivya@gmail.com wrote: There is a desert of 1000kms long. A camel is there and 3000 bananas. At one go a camel can take 1000 bananas. For each one km to walk camel eats 1 banana. How many bananas can we cross to the other side of desert -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] game of balls
Ram and Shyam are playing a game of balls. Ram choose a colour ball say red and shyam chose blue. Now both of them places the ball in a row with the condition that at any point the number of Shyam's balls can never be larger than Ram's. If both of them have equal number of balls say 'n' compute the number of ways in which all the 2n balls can be arranged. For n=3 number of ways would be 5 Find a linear solution for the same -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] coins
A table composed of N x M cells, each having a certain quantity of coins. You start from the upper-left corner. At each step you can go down or right one cell. Find the maximum number of coins you can collect. Provide an algorithm of O(n^2) solution. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Spoj- the next palindrome
got it.there was some logical error , i found it out.thanks in advance. On Tue, Dec 14, 2010 at 9:06 PM, Ankur Khurana ankur.kkhur...@gmail.com wrote: the question exactly was to find next palindrome just greater than the given no. The number could have a million digits. On Tue, Dec 14, 2010 at 9:01 PM, Ankur ankur.kkhur...@gmail.com wrote: hi, i was doing this problem : http://www.spoj.pl/problems/PALIN/ and i dont know why my solution was not giving AC . i have applied a simple strategy.if no. of digits are even , then mirror the first half and then add it to the first half. we get the plaindrome.if it is same as the given no. then just increment the first half and mirror it and add it to the first half again.Now also , the digits can be like this or 99 .I have made sure to treat this as a special case and my output for these is 10001 and 101 . I have applied a similar strategy for odd no of digits by increasing the middle elemnt and amirroring the first half around the middle element. here is the link to my solution http://paste.ubuntu.com/543644/ I would appreciate if anybody could help me here. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] C output... ???
#define SIZE 10 void size(int arr[SIZE]) { printf(size of array is:%d\n,sizeof(arr)); } int main() { int arr[SIZE]; size(arr); return 0; } the out put should be 40 considering 4 byte integer... but out put is only 4... how this is possible... and again if we modify it #define SIZE 10 int main() { int arr[SIZE]; printf(size of array is:%d\n,sizeof(arr)); return 0; } we are getting the desired output as 40 byte... thankyou in advance... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] C output... ???
When you pass an array as argument, it gets broken into a pointer. So you get size as 4 for 32 bit machine. On Tue, Dec 14, 2010 at 10:59 PM, Divesh Dixit dixit.coolfrog.div...@gmail.com wrote: #define SIZE 10 void size(int arr[SIZE]) { printf(size of array is:%d\n,sizeof(arr)); } int main() { int arr[SIZE]; size(arr); return 0; } the out put should be 40 considering 4 byte integer... but out put is only 4... how this is possible... and again if we modify it #define SIZE 10 int main() { int arr[SIZE]; printf(size of array is:%d\n,sizeof(arr)); return 0; } we are getting the desired output as 40 byte... thankyou in advance... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] C output... ???
When u r passing an array to a function u only pass the base address nt the total array...bt when sizeof is applied in main() u hv the whole array. Thats why in the first case the output is 4(only one address that is capable of holdin one integer)bt in the 2nd case the output is 40(as u hv 10 addresses each capable of holding an integer). On 12/14/10, Divesh Dixit dixit.coolfrog.div...@gmail.com wrote: #define SIZE 10 void size(int arr[SIZE]) { printf(size of array is:%d\n,sizeof(arr)); } int main() { int arr[SIZE]; size(arr); return 0; } the out put should be 40 considering 4 byte integer... but out put is only 4... how this is possible... and again if we modify it #define SIZE 10 int main() { int arr[SIZE]; printf(size of array is:%d\n,sizeof(arr)); return 0; } we are getting the desired output as 40 byte... thankyou in advance... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Amazon Interview Question
you can use hash table for this dude. On Dec 14, 8:22 pm, Prims topcode...@gmail.com wrote: given some positive numbers output the numbers in decreasing order of frequency..in case of a tie print the number which occurred first for eg: 1,3,3,1,2,3,5,2,3 the output should be 11225 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Amazon Interview Question
@sajj: if the range of number is not given then ? On Tue, Dec 14, 2010 at 11:41 PM, sajj sajjv...@gmail.com wrote: you can use hash table for this dude. On Dec 14, 8:22 pm, Prims topcode...@gmail.com wrote: given some positive numbers output the numbers in decreasing order of frequency..in case of a tie print the number which occurred first for eg: 1,3,3,1,2,3,5,2,3 the output should be 11225 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Amazon Interview Question
what you can do is create a vector pairint,int and sort it on the baisis of secondary key where it will be it's frequency. if tha range is not given. If the range is in permissible limits, then hash table is the answer. I suppose. On Tue, Dec 14, 2010 at 11:45 PM, Ankur Khurana ankur.kkhur...@gmail.com wrote: @sajj: if the range of number is not given then ? On Tue, Dec 14, 2010 at 11:41 PM, sajj sajjv...@gmail.com wrote: you can use hash table for this dude. On Dec 14, 8:22 pm, Prims topcode...@gmail.com wrote: given some positive numbers output the numbers in decreasing order of frequency..in case of a tie print the number which occurred first for eg: 1,3,3,1,2,3,5,2,3 the output should be 11225 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Learning new algorithms
Learning new algorithms -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Learning new algorithms
Learning new algorithms -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Amazon Interview Question
#include stdlib.h #includestdio.h #includeconio.h int main() { int array[]={1,3,3,1,2,3,5,2,3}; int size=sizeof(array)/sizeof(int); int min,max; max=min=array[0]; int i=0; for(i = 1; i size; i++) { if (array[i] min) min = array[i]; else if (array[i] max) max = array[i]; } int range = max - min + 1; int *count =(int *) malloc(range * sizeof(int)); for(i = 0; i size; i++) count[i] = 0; for(i = 0; i size; i++) count[array[i]]++; int pos=0; for(i=size-1;i=0;i--) { for(int j=0;jcount[i];j++) { array[pos]=i; pos++; } } //free(count); for(int i=0;isize;i++) printf(%d \n ,array[i]); getch(); } in case of a tie print the number which occurred first ...i think dis situation never occurs...as ..array is sorted.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] iTS aLL GOOGLE- iNTERVIEW
Write a C program which measures the the speed of a context switch on a UNIX/Linux system Regards Shashank Mani BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] iTS aLL GOOGLE- iNTERVIEW
How would you find out if a machine’s stack grows up or down in memory? can any one xplain wid program.. Regards Shashank Mani BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Adobe Interview Question
void foo1() { if(AB) Then {_/* */} else if(CD) then foo2() } How many time foo2() would get called given AB 25% of the times and CD 75% of the times and foo1() is called 5000 times although i had diff...solution..but i wants to confirm wid others..so hav a look Regards Shashank Mani BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] iTS aLL GOOGLE- iNTERVIEW
try this int p[100]; cout(p[1])-(p[0]); if it is positive, then the stack is growing upwards or else it is growing downwards. Not sure, please correct me if i am wrong. On Wed, Dec 15, 2010 at 12:32 AM, bittu shashank7andr...@gmail.com wrote: How would you find out if a machine’s stack grows up or down in memory? can any one xplain wid program.. Regards Shashank Mani BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] iTS aLL GOOGLE- iNTERVIEW
Below logic should tell us about the Machine Stack. let me know in case I am missing something. void check_for_stack(int a, int b) { unsigned int addr_1, addr_2; printf(%u %u\n, a, b); printf(0x%x 0x%x\n, a, b); if(a b) { printf(Machine Stack grows UP: Address keep decreasing); } else { printf(Machine stack grows down: Address Keep increasing); } } main() { int a,b; check_for_stack(a, b); } http://codepad.org/XGAbghDz On Tue, Dec 14, 2010 at 11:02 AM, bittu shashank7andr...@gmail.com wrote: How would you find out if a machine’s stack grows up or down in memory? can any one xplain wid program.. Regards Shashank Mani BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] iTS aLL GOOGLE- iNTERVIEW
mine did same job :) On Wed, Dec 15, 2010 at 12:41 AM, Anand anandut2...@gmail.com wrote: Below logic should tell us about the Machine Stack. let me know in case I am missing something. void check_for_stack(int a, int b) { unsigned int addr_1, addr_2; printf(%u %u\n, a, b); printf(0x%x 0x%x\n, a, b); if(a b) { printf(Machine Stack grows UP: Address keep decreasing); } else { printf(Machine stack grows down: Address Keep increasing); } } main() { int a,b; check_for_stack(a, b); } http://codepad.org/XGAbghDz On Tue, Dec 14, 2010 at 11:02 AM, bittu shashank7andr...@gmail.com wrote: How would you find out if a machine’s stack grows up or down in memory? can any one xplain wid program.. Regards Shashank Mani BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Adobe Interview Question
what i think is that the number of times foo2 being called is independent of the percentages given in the question it may be called 5000 times or 4999 times and continuinf in this fashion also none of the times as in every case there's 1/4 probability of AB and 3/4 of CD so as per me we cannot decide givn the percentage of success and failure any suggestions are always welcomed On Dec 15, 12:06 am, bittu shashank7andr...@gmail.com wrote: void foo1() { if(AB) Then {_/* */} else if(CD) then foo2() } How many time foo2() would get called given AB 25% of the times and CD 75% of the times and foo1() is called 5000 times although i had diff...solution..but i wants to confirm wid others..so hav a look Regards Shashank Mani BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] iTS aLL GOOGLE- iNTERVIEW
How abt this?? #includestdio.h #includeconio.h void checkStack(int i) { if(i!=0) { printf(%d in %u address space\n,i,i); checkStack(i-1); } } int main() { int i=10; checkStack(i); getch(); return 0; } Looking at the address in the output terminal we can get the ans... On 12/15/10, Ankur Khurana ankur.kkhur...@gmail.com wrote: mine did same job :) On Wed, Dec 15, 2010 at 12:41 AM, Anand anandut2...@gmail.com wrote: Below logic should tell us about the Machine Stack. let me know in case I am missing something. void check_for_stack(int a, int b) { unsigned int addr_1, addr_2; printf(%u %u\n, a, b); printf(0x%x 0x%x\n, a, b); if(a b) { printf(Machine Stack grows UP: Address keep decreasing); } else { printf(Machine stack grows down: Address Keep increasing); } } main() { int a,b; check_for_stack(a, b); } http://codepad.org/XGAbghDz On Tue, Dec 14, 2010 at 11:02 AM, bittu shashank7andr...@gmail.com wrote: How would you find out if a machine’s stack grows up or down in memory? can any one xplain wid program.. Regards Shashank Mani BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Adobe Interview Question
The function foo2 will be called iff the condition if(CD) evaluates to be true. Given that CD turns out to be true 75% times.So why the call to foo2 will be independent?? I think it is only the simple math.Correct me if I am wrong.. On 12/15/10, ankit sablok ankit4...@gmail.com wrote: what i think is that the number of times foo2 being called is independent of the percentages given in the question it may be called 5000 times or 4999 times and continuinf in this fashion also none of the times as in every case there's 1/4 probability of AB and 3/4 of CD so as per me we cannot decide givn the percentage of success and failure any suggestions are always welcomed On Dec 15, 12:06 am, bittu shashank7andr...@gmail.com wrote: void foo1() { if(AB) Then {_/* */} else if(CD) then foo2() } How many time foo2() would get called given AB 25% of the times and CD 75% of the times and foo1() is called 5000 times although i had diff...solution..but i wants to confirm wid others..so hav a look Regards Shashank Mani BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Google interview question
Read each file word by word and insert into a Suffix Tree... Terminal node of each word contains the FileNo/FileName... Quite simple On Dec 14, 5:42 pm, Tuaa vention.goth...@gmail.com wrote: According to me, the problem is regarding fastest search of substrings.. Hashing is one of the solutions. Use Rabin-Karp Search.. Use wiki at:http://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_string_search_algorit... On Dec 14, 4:01 pm, sourabh jakhar sourabhjak...@gmail.com wrote: i have a one idea in my mind is to implement a hash table structure based on 26 alphabets and a data structure of words. struct word { int info; char a[n];}; structure contains the info about the word and an array in which document it is present or not out of n ex if it is word is mnnit and it is in document 1 ,4,6,9 the info of the structure would be char[1,4,6,9]=1 and the rest are zero. insertion of word would take o(1) time but searching would take o(n) time if list is implemented as an array list and if implemented as an binary search tree would take it log(n) but than insertion would also take log(n) time On Mon, Dec 13, 2010 at 9:55 PM, GOBIND KUMAR gobind@gmail.com wrote: One of my friends attended google interview.This was one the question asked. you are given N documents(possibly in millions) with words in them. design datastructures such that the following scenarios take optimal time: a. print all the the docs having a given word b. print the docs having both of 2 given words Help me in solving this problem. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- SOURABH JAKHAR,(CSE)(3 year) ROOM NO 167 , TILAK,HOSTEL 'MNNIT ALLAHABAD- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] game of balls
the result is nth catalan number http://en.wikipedia.org/wiki/Catalan_number -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] coins
we can use DP to solve this: dp[i][j] = coins[i][j] + max ( dp[i-1][j] , dp[i][j-1] ) On Tue, Dec 14, 2010 at 7:24 PM, divya sweetdivya@gmail.com wrote: A table composed of N x M cells, each having a certain quantity of coins. You start from the upper-left corner. At each step you can go down or right one cell. Find the maximum number of coins you can collect. Provide an algorithm of O(n^2) solution. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Adobe Interview Question
2812.5 On Tue, Dec 14, 2010 at 10:36 PM, bittu shashank7andr...@gmail.com wrote: void foo1() { if(AB) Then {_/* */} else if(CD) then foo2() } How many time foo2() would get called given AB 25% of the times and CD 75% of the times and foo1() is called 5000 times although i had diff...solution..but i wants to confirm wid others..so hav a look Regards Shashank Mani BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: largest substring
Suffix trees efficiently solves the problem. Regards Aviral http://coders-stop.blogspot.com On Dec 14, 8:43 pm, divya sweetdivya@gmail.com wrote: Given a string, find the largest substring that occur multiple times within the same string. Extend your code to find the substring occuring atleast n times. Perform in linear time and space. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Adobe Interview Question
well i still believe that the calling of foo2 is independent plzzz suggest me the solution if i am wrong a detailed one thanx in advance On Wed, Dec 15, 2010 at 1:22 AM, Saurabh Koar saurabhkoar...@gmail.comwrote: The function foo2 will be called iff the condition if(CD) evaluates to be true. Given that CD turns out to be true 75% times.So why the call to foo2 will be independent?? I think it is only the simple math.Correct me if I am wrong.. On 12/15/10, ankit sablok ankit4...@gmail.com wrote: what i think is that the number of times foo2 being called is independent of the percentages given in the question it may be called 5000 times or 4999 times and continuinf in this fashion also none of the times as in every case there's 1/4 probability of AB and 3/4 of CD so as per me we cannot decide givn the percentage of success and failure any suggestions are always welcomed On Dec 15, 12:06 am, bittu shashank7andr...@gmail.com wrote: void foo1() { if(AB) Then {_/* */} else if(CD) then foo2() } How many time foo2() would get called given AB 25% of the times and CD 75% of the times and foo1() is called 5000 times although i had diff...solution..but i wants to confirm wid others..so hav a look Regards Shashank Mani BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] C output... ???
you would like to read peter ven der linden.(deep C secrets). On Tue, Dec 14, 2010 at 11:19 PM, Saurabh Koar saurabhkoar...@gmail.comwrote: When u r passing an array to a function u only pass the base address nt the total array...bt when sizeof is applied in main() u hv the whole array. Thats why in the first case the output is 4(only one address that is capable of holdin one integer)bt in the 2nd case the output is 40(as u hv 10 addresses each capable of holding an integer). On 12/14/10, Divesh Dixit dixit.coolfrog.div...@gmail.com wrote: #define SIZE 10 void size(int arr[SIZE]) { printf(size of array is:%d\n,sizeof(arr)); } int main() { int arr[SIZE]; size(arr); return 0; } the out put should be 40 considering 4 byte integer... but out put is only 4... how this is possible... and again if we modify it #define SIZE 10 int main() { int arr[SIZE]; printf(size of array is:%d\n,sizeof(arr)); return 0; } we are getting the desired output as 40 byte... thankyou in advance... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: largest substring
Does it include both overlapping and non-overlapping strings? On 14 December 2010 19:38, aviral gupta aviral@gmail.com wrote: Suffix trees efficiently solves the problem. Regards Aviral http://coders-stop.blogspot.com On Dec 14, 8:43 pm, divya sweetdivya@gmail.com wrote: Given a string, find the largest substring that occur multiple times within the same string. Extend your code to find the substring occuring atleast n times. Perform in linear time and space. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- regards, soumya prasad ukil -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Amazon Interview Question
bittu, in stead of writing your code, put your logic here. It is not the place to show how capable one is to write a program. On 14 December 2010 11:00, bittu shashank7andr...@gmail.com wrote: #include stdlib.h #includestdio.h #includeconio.h int main() { int array[]={1,3,3,1,2,3,5,2,3}; int size=sizeof(array)/sizeof(int); int min,max; max=min=array[0]; int i=0; for(i = 1; i size; i++) { if (array[i] min) min = array[i]; else if (array[i] max) max = array[i]; } int range = max - min + 1; int *count =(int *) malloc(range * sizeof(int)); for(i = 0; i size; i++) count[i] = 0; for(i = 0; i size; i++) count[array[i]]++; int pos=0; for(i=size-1;i=0;i--) { for(int j=0;jcount[i];j++) { array[pos]=i; pos++; } } //free(count); for(int i=0;isize;i++) printf(%d \n ,array[i]); getch(); } in case of a tie print the number which occurred first ...i think dis situation never occurs...as ..array is sorted.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- regards, soumya prasad ukil -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] linkd list
Are the linked list sorted? On 14 December 2010 05:33, divya sweetdivya@gmail.com wrote: Given three lists: A, B and C of length n each. Write a function which returns true if any 3 three numbers (1 from each list), sum up to zero. Else return false, if there is no such combination. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- regards, soumya prasad ukil -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Adobe Interview Question
(1-0.25)* 0.75*5000 = 2812.5 On Wed, Dec 15, 2010 at 9:31 AM, ankit sablok ankit4...@gmail.com wrote: well i still believe that the calling of foo2 is independent plzzz suggest me the solution if i am wrong a detailed one thanx in advance On Wed, Dec 15, 2010 at 1:22 AM, Saurabh Koar saurabhkoar...@gmail.comwrote: The function foo2 will be called iff the condition if(CD) evaluates to be true. Given that CD turns out to be true 75% times.So why the call to foo2 will be independent?? I think it is only the simple math.Correct me if I am wrong.. On 12/15/10, ankit sablok ankit4...@gmail.com wrote: what i think is that the number of times foo2 being called is independent of the percentages given in the question it may be called 5000 times or 4999 times and continuinf in this fashion also none of the times as in every case there's 1/4 probability of AB and 3/4 of CD so as per me we cannot decide givn the percentage of success and failure any suggestions are always welcomed On Dec 15, 12:06 am, bittu shashank7andr...@gmail.com wrote: void foo1() { if(AB) Then {_/* */} else if(CD) then foo2() } How many time foo2() would get called given AB 25% of the times and CD 75% of the times and foo1() is called 5000 times although i had diff...solution..but i wants to confirm wid others..so hav a look Regards Shashank Mani BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Adobe Interview Question
@Sravan: Plz explain the logic.. On 12/15/10, Sravan Akepati sravan.akep...@gmail.com wrote: (1-0.25)* 0.75*5000 = 2812.5 On Wed, Dec 15, 2010 at 9:31 AM, ankit sablok ankit4...@gmail.com wrote: well i still believe that the calling of foo2 is independent plzzz suggest me the solution if i am wrong a detailed one thanx in advance On Wed, Dec 15, 2010 at 1:22 AM, Saurabh Koar saurabhkoar...@gmail.comwrote: The function foo2 will be called iff the condition if(CD) evaluates to be true. Given that CD turns out to be true 75% times.So why the call to foo2 will be independent?? I think it is only the simple math.Correct me if I am wrong.. On 12/15/10, ankit sablok ankit4...@gmail.com wrote: what i think is that the number of times foo2 being called is independent of the percentages given in the question it may be called 5000 times or 4999 times and continuinf in this fashion also none of the times as in every case there's 1/4 probability of AB and 3/4 of CD so as per me we cannot decide givn the percentage of success and failure any suggestions are always welcomed On Dec 15, 12:06 am, bittu shashank7andr...@gmail.com wrote: void foo1() { if(AB) Then {_/* */} else if(CD) then foo2() } How many time foo2() would get called given AB 25% of the times and CD 75% of the times and foo1() is called 5000 times although i had diff...solution..but i wants to confirm wid others..so hav a look Regards Shashank Mani BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] linkd list
@Divya, I think you ask this question before. Not sure of the answer though :) On Tue, Dec 14, 2010 at 9:06 PM, Soumya Prasad Ukil ukil.sou...@gmail.comwrote: Are the linked list sorted? On 14 December 2010 05:33, divya sweetdivya@gmail.com wrote: Given three lists: A, B and C of length n each. Write a function which returns true if any 3 three numbers (1 from each list), sum up to zero. Else return false, if there is no such combination. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- regards, soumya prasad ukil -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Adobe Interview Question
@Sravan There seems to be a little problem in your solution. Your are probably assuming that 75% of C is less than D after the condition that A is greater than B while thats not the case according to the question. My Solution - Out of 5000 cases, AB in 3750 of them and CD in 3750 of them again. Thus, foo2 should run atleast 2500 times and not more than 3750 times depending on the input combinations. On Wed, Dec 15, 2010 at 11:35 AM, Saurabh Koar saurabhkoar...@gmail.comwrote: @Sravan: Plz explain the logic.. On 12/15/10, Sravan Akepati sravan.akep...@gmail.com wrote: (1-0.25)* 0.75*5000 = 2812.5 On Wed, Dec 15, 2010 at 9:31 AM, ankit sablok ankit4...@gmail.com wrote: well i still believe that the calling of foo2 is independent plzzz suggest me the solution if i am wrong a detailed one thanx in advance On Wed, Dec 15, 2010 at 1:22 AM, Saurabh Koar saurabhkoar...@gmail.comwrote: The function foo2 will be called iff the condition if(CD) evaluates to be true. Given that CD turns out to be true 75% times.So why the call to foo2 will be independent?? I think it is only the simple math.Correct me if I am wrong.. On 12/15/10, ankit sablok ankit4...@gmail.com wrote: what i think is that the number of times foo2 being called is independent of the percentages given in the question it may be called 5000 times or 4999 times and continuinf in this fashion also none of the times as in every case there's 1/4 probability of AB and 3/4 of CD so as per me we cannot decide givn the percentage of success and failure any suggestions are always welcomed On Dec 15, 12:06 am, bittu shashank7andr...@gmail.com wrote: void foo1() { if(AB) Then {_/* */} else if(CD) then foo2() } How many time foo2() would get called given AB 25% of the times and CD 75% of the times and foo1() is called 5000 times although i had diff...solution..but i wants to confirm wid others..so hav a look Regards Shashank Mani BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com algogeeks%2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com algogeeks%2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com algogeeks%2bunsubscr...@googlegroups.comalgogeeks%252bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Amazon Interview Question
I think ankur khanna's solution is appropriate. couldn't get what bittu was trying to do completely.. could you just explain it once please! On Wed, Dec 15, 2010 at 10:35 AM, Soumya Prasad Ukil ukil.sou...@gmail.comwrote: bittu, in stead of writing your code, put your logic here. It is not the place to show how capable one is to write a program. On 14 December 2010 11:00, bittu shashank7andr...@gmail.com wrote: #include stdlib.h #includestdio.h #includeconio.h int main() { int array[]={1,3,3,1,2,3,5,2,3}; int size=sizeof(array)/sizeof(int); int min,max; max=min=array[0]; int i=0; for(i = 1; i size; i++) { if (array[i] min) min = array[i]; else if (array[i] max) max = array[i]; } int range = max - min + 1; int *count =(int *) malloc(range * sizeof(int)); for(i = 0; i size; i++) count[i] = 0; for(i = 0; i size; i++) count[array[i]]++; int pos=0; for(i=size-1;i=0;i--) { for(int j=0;jcount[i];j++) { array[pos]=i; pos++; } } //free(count); for(int i=0;isize;i++) printf(%d \n ,array[i]); getch(); } in case of a tie print the number which occurred first ...i think dis situation never occurs...as ..array is sorted.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- regards, soumya prasad ukil -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: largest substring
@aviral - could you please explain it a little further? i was unable to interpret your solution On Wed, Dec 15, 2010 at 10:32 AM, Soumya Prasad Ukil ukil.sou...@gmail.comwrote: Does it include both overlapping and non-overlapping strings? On 14 December 2010 19:38, aviral gupta aviral@gmail.com wrote: Suffix trees efficiently solves the problem. Regards Aviral http://coders-stop.blogspot.com On Dec 14, 8:43 pm, divya sweetdivya@gmail.com wrote: Given a string, find the largest substring that occur multiple times within the same string. Extend your code to find the substring occuring atleast n times. Perform in linear time and space. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- regards, soumya prasad ukil -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Adobe Interview Question
Hi! Assume 5000 test cases of A,B,C,D.. and The probabilities are as mentioned above. Then If loop will fail for 75% of test cases and else will be executed.. In that 75% test cases, only 75% test cases will satisfy the inner if statement.. So 3/4 * 3/4 = 9/16. 9/16 * 5000 = 2812.. I guess that 'll do. :) On Dec 14, 10:05 pm, Saurabh Koar saurabhkoar...@gmail.com wrote: @Sravan: Plz explain the logic.. On 12/15/10, Sravan Akepati sravan.akep...@gmail.com wrote: (1-0.25)* 0.75*5000 = 2812.5 On Wed, Dec 15, 2010 at 9:31 AM, ankit sablok ankit4...@gmail.com wrote: well i still believe that the calling of foo2 is independent plzzz suggest me the solution if i am wrong a detailed one thanx in advance On Wed, Dec 15, 2010 at 1:22 AM, Saurabh Koar saurabhkoar...@gmail.comwrote: The function foo2 will be called iff the condition if(CD) evaluates to be true. Given that CD turns out to be true 75% times.So why the call to foo2 will be independent?? I think it is only the simple math.Correct me if I am wrong.. On 12/15/10, ankit sablok ankit4...@gmail.com wrote: what i think is that the number of times foo2 being called is independent of the percentages given in the question it may be called 5000 times or 4999 times and continuinf in this fashion also none of the times as in every case there's 1/4 probability of AB and 3/4 of CD so as per me we cannot decide givn the percentage of success and failure any suggestions are always welcomed On Dec 15, 12:06 am, bittu shashank7andr...@gmail.com wrote: void foo1() { if(AB) Then {_/* */} else if(CD) then foo2() } How many time foo2() would get called given AB 25% of the times and CD 75% of the times and foo1() is called 5000 times although i had diff...solution..but i wants to confirm wid others..so hav a look Regards Shashank Mani BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups .com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups .com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups .com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Adobe Interview Question
i think sravan is right. we go to CD condition after AB have failed. For that to happen, we have prob. of .75 . now the probability of CD is .75 . so total probability is .75 * .75 as both are mutualy exclusive events. so total no. foo2 is called is 2812.5 . On Wed, Dec 15, 2010 at 11:55 AM, Ankur Murarka ankur.murarka@gmail.com wrote: @Sravan There seems to be a little problem in your solution. Your are probably assuming that 75% of C is less than D after the condition that A is greater than B while thats not the case according to the question. My Solution - Out of 5000 cases, AB in 3750 of them and CD in 3750 of them again. Thus, foo2 should run atleast 2500 times and not more than 3750 times depending on the input combinations. On Wed, Dec 15, 2010 at 11:35 AM, Saurabh Koar saurabhkoar...@gmail.com wrote: @Sravan: Plz explain the logic.. On 12/15/10, Sravan Akepati sravan.akep...@gmail.com wrote: (1-0.25)* 0.75*5000 = 2812.5 On Wed, Dec 15, 2010 at 9:31 AM, ankit sablok ankit4...@gmail.com wrote: well i still believe that the calling of foo2 is independent plzzz suggest me the solution if i am wrong a detailed one thanx in advance On Wed, Dec 15, 2010 at 1:22 AM, Saurabh Koar saurabhkoar...@gmail.comwrote: The function foo2 will be called iff the condition if(CD) evaluates to be true. Given that CD turns out to be true 75% times.So why the call to foo2 will be independent?? I think it is only the simple math.Correct me if I am wrong.. On 12/15/10, ankit sablok ankit4...@gmail.com wrote: what i think is that the number of times foo2 being called is independent of the percentages given in the question it may be called 5000 times or 4999 times and continuinf in this fashion also none of the times as in every case there's 1/4 probability of AB and 3/4 of CD so as per me we cannot decide givn the percentage of success and failure any suggestions are always welcomed On Dec 15, 12:06 am, bittu shashank7andr...@gmail.com wrote: void foo1() { if(AB) Then {_/* */} else if(CD) then foo2() } How many time foo2() would get called given AB 25% of the times and CD 75% of the times and foo1() is called 5000 times although i had diff...solution..but i wants to confirm wid others..so hav a look Regards Shashank Mani BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group
Re: [algogeeks] iTS aLL GOOGLE- iNTERVIEW
Saurabh : good one :) On Wed, Dec 15, 2010 at 1:15 AM, Saurabh Koar saurabhkoar...@gmail.com wrote: How abt this?? #includestdio.h #includeconio.h void checkStack(int i) { if(i!=0) { printf(%d in %u address space\n,i,i); checkStack(i-1); } } int main() { int i=10; checkStack(i); getch(); return 0; } Looking at the address in the output terminal we can get the ans... On 12/15/10, Ankur Khurana ankur.kkhur...@gmail.com wrote: mine did same job :) On Wed, Dec 15, 2010 at 12:41 AM, Anand anandut2...@gmail.com wrote: Below logic should tell us about the Machine Stack. let me know in case I am missing something. void check_for_stack(int a, int b) { unsigned int addr_1, addr_2; printf(%u %u\n, a, b); printf(0x%x 0x%x\n, a, b); if(a b) { printf(Machine Stack grows UP: Address keep decreasing); } else { printf(Machine stack grows down: Address Keep increasing); } } main() { int a,b; check_for_stack(a, b); } http://codepad.org/XGAbghDz On Tue, Dec 14, 2010 at 11:02 AM, bittu shashank7andr...@gmail.com wrote: How would you find out if a machine’s stack grows up or down in memory? can any one xplain wid program.. Regards Shashank Mani BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] coins
how do we find the complexity of DP program ? i know it cn be done using DP states , but the gien complexity is n^2 . i am not sure how to compare that On Tue, Dec 14, 2010 at 11:41 PM, Amir hossein Shahriari amir.hossein.shahri...@gmail.com wrote: we can use DP to solve this: dp[i][j] = coins[i][j] + max ( dp[i-1][j] , dp[i][j-1] ) On Tue, Dec 14, 2010 at 7:24 PM, divya sweetdivya@gmail.com wrote: A table composed of N x M cells, each having a certain quantity of coins. You start from the upper-left corner. At each step you can go down or right one cell. Find the maximum number of coins you can collect. Provide an algorithm of O(n^2) solution. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Adobe Interview Question
I think, we must give answers in the range.. See, what happens if the Test cases which doesn't satisfy (AB) can be the test cases which satisfy the condition (CD) In that scenario, !(AB) and (CD) co-occurs, Ouput will be 3/4 *1 * 5000 = 3750.. o.w, Worst case , 3/4 * 2/3 * 5000 = 2500 .. Range - 2500 x 3750 Correct me if i am wrong.. :) On Dec 14, 10:37 pm, Ankur Khurana ankur.kkhur...@gmail.com wrote: i think sravan is right. we go to CD condition after AB have failed. For that to happen, we have prob. of .75 . now the probability of CD is .75 . so total probability is .75 * .75 as both are mutualy exclusive events. so total no. foo2 is called is 2812.5 . On Wed, Dec 15, 2010 at 11:55 AM, Ankur Murarka ankur.murarka@gmail.com wrote: @Sravan There seems to be a little problem in your solution. Your are probably assuming that 75% of C is less than D after the condition that A is greater than B while thats not the case according to the question. My Solution - Out of 5000 cases, AB in 3750 of them and CD in 3750 of them again. Thus, foo2 should run atleast 2500 times and not more than 3750 times depending on the input combinations. On Wed, Dec 15, 2010 at 11:35 AM, Saurabh Koar saurabhkoar...@gmail.com wrote: @Sravan: Plz explain the logic.. On 12/15/10, Sravan Akepati sravan.akep...@gmail.com wrote: (1-0.25)* 0.75*5000 = 2812.5 On Wed, Dec 15, 2010 at 9:31 AM, ankit sablok ankit4...@gmail.com wrote: well i still believe that the calling of foo2 is independent plzzz suggest me the solution if i am wrong a detailed one thanx in advance On Wed, Dec 15, 2010 at 1:22 AM, Saurabh Koar saurabhkoar...@gmail.comwrote: The function foo2 will be called iff the condition if(CD) evaluates to be true. Given that CD turns out to be true 75% times.So why the call to foo2 will be independent?? I think it is only the simple math.Correct me if I am wrong.. On 12/15/10, ankit sablok ankit4...@gmail.com wrote: what i think is that the number of times foo2 being called is independent of the percentages given in the question it may be called 5000 times or 4999 times and continuinf in this fashion also none of the times as in every case there's 1/4 probability of AB and 3/4 of CD so as per me we cannot decide givn the percentage of success and failure any suggestions are always welcomed On Dec 15, 12:06 am, bittu shashank7andr...@gmail.com wrote: void foo1() { if(AB) Then {_/* */} else if(CD) then foo2() } How many time foo2() would get called given AB 25% of the times and CD 75% of the times and foo1() is called 5000 times although i had diff...solution..but i wants to confirm wid others..so hav a look Regards Shashank Mani BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups .com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups .com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups .com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this
Re: [algogeeks] Re: Adobe Interview Question
it' probability , how do we define best or worst in probability ? On Wed, Dec 15, 2010 at 12:25 PM, Kathir kathirch...@gmail.com wrote: I think, we must give answers in the range.. See, what happens if the Test cases which doesn't satisfy (AB) can be the test cases which satisfy the condition (CD) In that scenario, !(AB) and (CD) co-occurs, Ouput will be 3/4 *1 * 5000 = 3750.. o.w, Worst case , 3/4 * 2/3 * 5000 = 2500 .. Range - 2500 x 3750 Correct me if i am wrong.. :) On Dec 14, 10:37 pm, Ankur Khurana ankur.kkhur...@gmail.com wrote: i think sravan is right. we go to CD condition after AB have failed. For that to happen, we have prob. of .75 . now the probability of CD is .75 . so total probability is .75 * .75 as both are mutualy exclusive events. so total no. foo2 is called is 2812.5 . On Wed, Dec 15, 2010 at 11:55 AM, Ankur Murarka ankur.murarka@gmail.com wrote: @Sravan There seems to be a little problem in your solution. Your are probably assuming that 75% of C is less than D after the condition that A is greater than B while thats not the case according to the question. My Solution - Out of 5000 cases, AB in 3750 of them and CD in 3750 of them again. Thus, foo2 should run atleast 2500 times and not more than 3750 times depending on the input combinations. On Wed, Dec 15, 2010 at 11:35 AM, Saurabh Koar saurabhkoar...@gmail.com wrote: @Sravan: Plz explain the logic.. On 12/15/10, Sravan Akepati sravan.akep...@gmail.com wrote: (1-0.25)* 0.75*5000 = 2812.5 On Wed, Dec 15, 2010 at 9:31 AM, ankit sablok ankit4...@gmail.com wrote: well i still believe that the calling of foo2 is independent plzzz suggest me the solution if i am wrong a detailed one thanx in advance On Wed, Dec 15, 2010 at 1:22 AM, Saurabh Koar saurabhkoar...@gmail.comwrote: The function foo2 will be called iff the condition if(CD) evaluates to be true. Given that CD turns out to be true 75% times.So why the call to foo2 will be independent?? I think it is only the simple math.Correct me if I am wrong.. On 12/15/10, ankit sablok ankit4...@gmail.com wrote: what i think is that the number of times foo2 being called is independent of the percentages given in the question it may be called 5000 times or 4999 times and continuinf in this fashion also none of the times as in every case there's 1/4 probability of AB and 3/4 of CD so as per me we cannot decide givn the percentage of success and failure any suggestions are always welcomed On Dec 15, 12:06 am, bittu shashank7andr...@gmail.com wrote: void foo1() { if(AB) Then {_/* */} else if(CD) then foo2() } How many time foo2() would get called given AB 25% of the times and CD 75% of the times and foo1() is called 5000 times although i had diff...solution..but i wants to confirm wid others..so hav a look Regards Shashank Mani BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups .com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups .com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups .com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at
[algogeeks] Maximum Sub Sequence of 1s and 0s
You are given an array ' containing 0s and 1s. Find O(n) time and O(1) space algorithm to find the maximum sub sequence which has equal number of 1s and 0s. Examples 1) 10101010 The longest sub sequence that satisfies the problem is the input itself 2)1101000 The longest sub sequence that satisfies the problem is 110100 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.