Re: [algogeeks] Contiguous subarray with sum zero
Hey there are three answers for the given example. But you solution will give only 2 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@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] Contiguous subarray with sum zero
Sorry. This will work Best Regards, -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@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] MS: BST
We need all pairs. Best Regards, T V Thirumala Reddy On Mon, Jul 11, 2011 at 3:56 PM, saurabh singh saurab...@gmail.com wrote: Ok lets see. 1-Traverse a pointer right down to the leftmost element,i.e.the shortest,say small 2-traverse a pointer left down to the rightmost element i.e.the largest.say large while(small!=large) 3-Compare their sum.If sumk set large to its successor in reverse inorder.(I am not sure if u meant the same but I am assuming rev inorder to be right-node-left) else set small to its inorder successor. break when u get the desired k. print :) return if u get out of the loop without getting the number then such number does not exist.print :( On Mon, Jul 11, 2011 at 3:16 PM, aanchal goyal goyal.aanch...@gmail.comwrote: we should not deform the tree. - converting into dll and solving. - doing inorder and hashing - doing inorder and saving in array All above solutions I know, so dont post them, i dont know how to solve this using inorder and reverse inorder approach.. On Mon, Jul 11, 2011 at 3:13 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: If we dont want the tree back, we can convert the BST to DLL and do the job.. On Mon, Jul 11, 2011 at 3:01 PM, aanchal goyal goyal.aanch...@gmail.com wrote: Given a BST and integer value K. Find all pairs of nodes (x,y), such that x-data + y-data = K Time O(n) Can someone provide a pseudocode/code to solve this using the concept of inorder and reverse inorder traversal of BST? PS: please don't post other solutions for this, I know this can be solved in other ways too. I am not able to code this using the above concept.. -- Regards,* Aanchal Goyal*. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@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. -- *Piyush Sinha* *IIIT, Allahabad* *+91-8792136657* *+91-7483122727* *https://www.facebook.com/profile.php?id=10655377926 * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@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. -- Regards,* Aanchal Goyal*. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@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. -- Saurabh Singh B.Tech (Computer Science) 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 algogeeks@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 algogeeks@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] MS: BST
what is the complexity of your alg? Best Regards, T V Thirumala Reddy On Mon, Jul 11, 2011 at 4:02 PM, TIRU REDDY tiru...@gmail.com wrote: We need all pairs. Best Regards, T V Thirumala Reddy On Mon, Jul 11, 2011 at 3:56 PM, saurabh singh saurab...@gmail.comwrote: Ok lets see. 1-Traverse a pointer right down to the leftmost element,i.e.the shortest,say small 2-traverse a pointer left down to the rightmost element i.e.the largest.say large while(small!=large) 3-Compare their sum.If sumk set large to its successor in reverse inorder.(I am not sure if u meant the same but I am assuming rev inorder to be right-node-left) else set small to its inorder successor. break when u get the desired k. print :) return if u get out of the loop without getting the number then such number does not exist.print :( On Mon, Jul 11, 2011 at 3:16 PM, aanchal goyal goyal.aanch...@gmail.comwrote: we should not deform the tree. - converting into dll and solving. - doing inorder and hashing - doing inorder and saving in array All above solutions I know, so dont post them, i dont know how to solve this using inorder and reverse inorder approach.. On Mon, Jul 11, 2011 at 3:13 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: If we dont want the tree back, we can convert the BST to DLL and do the job.. On Mon, Jul 11, 2011 at 3:01 PM, aanchal goyal goyal.aanch...@gmail.com wrote: Given a BST and integer value K. Find all pairs of nodes (x,y), such that x-data + y-data = K Time O(n) Can someone provide a pseudocode/code to solve this using the concept of inorder and reverse inorder traversal of BST? PS: please don't post other solutions for this, I know this can be solved in other ways too. I am not able to code this using the above concept.. -- Regards,* Aanchal Goyal*. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@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. -- *Piyush Sinha* *IIIT, Allahabad* *+91-8792136657* *+91-7483122727* *https://www.facebook.com/profile.php?id=10655377926 * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@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. -- Regards,* Aanchal Goyal*. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@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. -- Saurabh Singh B.Tech (Computer Science) 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 algogeeks@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 algogeeks@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] An interview querstion
Today I attended an interview. Just wanna share a good Q. Rows are represented using alphabets. Example: first row - 'A' second row: 'B' . . . 26th row : 'Z' 27th: 'AA' . . Now given a number, we need to find the corresponding alphabet representation. Say Given 78 Answer should be BZ Given 26 answer should be Z Given 27 answer should be AA Solution: Number of rows with single alphabet = 26. and range is 1 to 26 Number of rows with 2 alphabets = 26*26 and range is 27 to 702 ... IDEA: Sum of n terms in GP = a(r^n-1)/(r-1) long int GP_SUM(int i) { return 26(pow(26,i)-1)/(25); } char getChar(int i) { return ABCDEFGHIJKLMNOPQRSTUVWXYZ[i-1]; } Given 1202. 1202 GP_SUM(2) 1202 = GP_SUM(3) So it should be 3 alphabet. 1202-GP_SUM(2) = 500. Using 500 we need to compute the result. 500/pow(26,2) = 0, so last one is A 500/pow(26,1) = 19 with remainder 6. so second last one is T (20th char because remainder is non zero) remainder is 6 so third one is F Ans:ATF. Thank you. Best Regards, T V Thirumala Reddy Engineer, Qualcomm India Private Ltd. 1540C30, 15th Floor, Building #9, Mindspace, Hitech city, Madhapur, Hyderabad-81. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@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: An interview querstion
Agreed. On 11 Jul 2011 00:38, DK divyekap...@gmail.com wrote: The answer is a simple encoding of the number in base 26. There is no need to calculate anything else. -- DK http://twitter.com/divyekapoor http://www.divye.in -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/WHcSXaMs0JwJ. To post to this group, send email to algogeeks@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 algogeeks@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] puzzle
14 On 6 Jul 2011 22:35, shiv narayan narayan.shiv...@gmail.com wrote: * You are given 2 eggs. * You have access to a 100-storey building. * Eggs can be very hard or very fragile means it may break if dropped from the first floor or may not even break if dropped from 100 th floor.Both eggs are identical. * You need to figure out the highest floor of a 100-storey building an egg can be dropped without breaking. * Now the question is how many drops you need to make. You are allowed to break 2 eggs in the process -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@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 algogeeks@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] puzzle
s(s+1)/2 must be close to 100. The best possible number is 14. try from 14th floor. next from 14+13th floor. next from 14+13+12th floor. Worest case number of attempts = 14. Best Regards, T V Thirumala Reddy Engineer, Qualcomm India Private Ltd. 1540C30, 15th Floor, Building #9, Mindspace, Hitech city, Madhapur, Hyderabad-81. On Wed, Jul 6, 2011 at 11:14 PM, Sriganesh Krishnan 2448...@gmail.comwrote: @tiru and @aseem: explanation pls...! On Wed, Jul 6, 2011 at 11:11 PM, TIRU REDDY tiru...@gmail.com wrote: 14 On 6 Jul 2011 22:35, shiv narayan narayan.shiv...@gmail.com wrote: * You are given 2 eggs. * You have access to a 100-storey building. * Eggs can be very hard or very fragile means it may break if dropped from the first floor or may not even break if dropped from 100 th floor.Both eggs are identical. * You need to figure out the highest floor of a 100-storey building an egg can be dropped without breaking. * Now the question is how many drops you need to make. You are allowed to break 2 eggs in the process -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@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 algogeeks@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 algogeeks@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 algogeeks@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] Random Number Generator
how about a*rand(0,1)+b? On Wed, Jul 6, 2011 at 11:20 PM, Nitish Garg nitishgarg1...@gmail.comwrote: implementation of Random(a, b) that only make calls to Random(0, 1) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@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.