Re: [algogeeks] Google Interview Question
I think what' required is that we compare digits - eg. 18 187 Since last digit of second num > First digit of first number - 18718 48 482 Since last digit of second num < First digit of first number - 48482 --Anurag On Mon, May 30, 2011 at 3:38 PM, Piyush Sinha wrote: > @Bhavesh... > > for the inputs 18,187.. apply your method.. > 18 -- 188 > 187-- 187 > 18187 -> ur method > 18718 -> actual > > On Mon, May 30, 2011 at 3:28 PM, Bhavesh agrawal > wrote: >> >> solution may be >> >> array ={ 3 ,21 ,9 ,93,17 ,178 ,1,101} (i think i have covered all >> exceptions ) >> then ,change this array like 3 , 21222, 9, 93999, 17111, 17811, >> 1 , 10111 ( make each number of 5 digit with rest digits same as Ist >> digit ) >> then sort this array >> 9, 93999,3 21222, 17811,17111, 1, 10111 >> and make it with actual numbers >> 9,93,3,21,178,17,1,101 = 993321178171101 >> plz let me know if any case left... >> >> -- >> 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. > -- 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 interview question
Have a look at this recursive soln in java - Node convertList(Node head) { if(head ==null) return null; Node node = head; Node next = node.next; Node next2next = next.next; next.next = node; node.next = convertList(next2next); return next; } This soln assumes even number of nodes in the list. The code is quite self explanatory. --Anurag On Wed, Jun 1, 2011 at 6:26 AM, Anand wrote: > Given a linked list of the form, 1->2->3->4->5->6, convert it into the form > 2->1->4->3->6->5. Note that the nodes need to be altered and not the data > contained in them > > -- > 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] Array problem
Just need some clarification; sorry I joined the thread late. What are we trying maximize? A[j] -A[i] such that i wrote: > @ Piyush: Excellent Solution...It appears both Correct and O(n)...Good work > !![?] > > Just a minor correction in your algo.[?] > > * while(B[i] * j++; > must also check for J's bound as: > **while ( j < ( sizeof(A)/sizeof(A[0]) )* && *B[i] j++; > Or it will crash when J goes out of bound and we try to reference C[j]. > > Nywayz..thnx for the solution and algo !! > * > > -- > 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. <<363.gif>><<360.gif>>
Re: [algogeeks] Do you Think Allocating memory to 2D Array is easy ???
A small correction - To access - arr[i][j] => get the memory location by m*i+j. On Fri, Apr 29, 2011 at 6:25 PM, Anurag Bhatia wrote: > I have not written code in C for a while, so pardon any gaffes. > > Let us say the dimensions of the array to be created are m and n. > To create the array - (int *)malloc(sizeof(int)*m*n); > To access - arr[i][j] => get the memory location by n*i+j. > > --Anurag > > > > On Fri, Apr 29, 2011 at 6:00 PM, bittu wrote: >> Basically we have to implement function which allocates memory to a >> two dimensional array. we have to Minimize the number of calls to >> malloc and make sure that the memory is accessible by the notation >> arr[i][j]. >> >> .important part of the question is we have to implement the it using >> single call to MALLOC..its strictly means only 1 time ?? so make sure >> your not calling malloc more then 1 so lets make our hand dirty..?? >> >> Please Read Question Carefully... >> >> >> >> >> >> Thanks & Regrads >> Shashank >> >> -- >> 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] Do you Think Allocating memory to 2D Array is easy ???
I have not written code in C for a while, so pardon any gaffes. Let us say the dimensions of the array to be created are m and n. To create the array - (int *)malloc(sizeof(int)*m*n); To access - arr[i][j] => get the memory location by n*i+j. --Anurag On Fri, Apr 29, 2011 at 6:00 PM, bittu wrote: > Basically we have to implement function which allocates memory to a > two dimensional array. we have to Minimize the number of calls to > malloc and make sure that the memory is accessible by the notation > arr[i][j]. > > .important part of the question is we have to implement the it using > single call to MALLOC..its strictly means only 1 time ?? so make sure > your not calling malloc more then 1 so lets make our hand dirty..?? > > Please Read Question Carefully... > > > > > > Thanks & Regrads > Shashank > > -- > 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] Re: Median of Binary Tree
@bittu: Can we modify the tree to store extra info? On Mon, Mar 28, 2011 at 4:16 PM, bittu wrote: > @all try to understand the question as usual we have to do it in min. > time & space complexity ..in mean Time O(n) & space o(1) At-most > just tell em after doing in-order traversal where u will store the > elements either in array or in set isn'tit it will take O(n) extra > space why not looks fro O(1) SPACE..IF M NOT CORRECT otherwise problem > just become finding median in array which O(1) ..correct me if m > wrong > > @Anurag wher u will store inorder of tree > > > Thanks > Shashank > > -- > 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] Re: Median of Binary Tree
You could do any order traversal to get the list of values. - O(n) Apply the kth order statistic (where k = numNodes/2) to get the value - O(n) Adjust the median depending on whether numNode is odd or even On Sun, Mar 27, 2011 at 8:03 PM, Balaji Ramani wrote: > Hi, > > This is one approach to it: > > 1) Go to the first node in inorder traversal. Let the pointer be LP. > (Push the intermediate nodes to Lstack while doing this ) > 2) Go to the last node in inorder traversal. Let the pointer be RP. > (Push the intermediate nodes to Rstack while doing this ) > > while(LP->data < RP->data){ > LP = inordersuccessor(LP,Lstack) > // gets inorder successor and modifies Lstack accordingly > RP = inorderpredecessor(RP,Rstack) > // gets inorder predecessor and modifies Rstack accordingly > Lprev = LP > Rprev = RP; > } > > if(LP->data = RP->data){ // even number of elements > retrun LP->data; > }else{ > return Lprev->data + Rprev->data / 2 > } > > Time: O(n) > Memory: 2 * O ( log n) average > > Thanks, > Balaji. > > On Sun, Mar 27, 2011 at 7:17 PM, bittu wrote: >> >> @all >> >> wake up geeks >> >> >> Thanks >> Shashank >> >> -- >> 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.
[algogeeks] Amazon Online Test
Has anyone give any first round online test for Amazon? If yes, can you please share details? --Anurag -- 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: Microsoft Written Test Questions
Does anyone have details of whether the test was conducted on the 30th? If yes, which city? --AB On Thu, Jan 27, 2011 at 5:33 PM, Rahul Menon wrote: > This time MS rather than conducting the written tests by itself has > outsourced the procedure to MERITTRAC Services to be conducted to jan > 30th, So unlike the regular 6 questions type written test , it will be > replaced by MCQs which is the regular pattern of merittrac tests > [think so] . From a bit googling I came to know that these people put > lot of repeated questions and each time and if we can get questions > from previously conducted tests of MS , it can be very helpful. > > So the ones with experience with merritrac tests here ,can do a lot > help, > > I would also like to know about the pattern or topics they usually > test. And also sample questions > > > > Regards, > > Rahul > > -- > 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] Frequently one of the Top Question Asked in Amazon
@bittu: Can you give and example?? I am unable to understand what a spiral order is? On Sat, Jan 29, 2011 at 8:25 PM, bittu wrote: > Convert BT in to DLL such that DLL represents the Sprial order > traversal of BT. > > "Inplace" > > its Written Test Question & They wants Exact Working Code...Not > Approach..Be Clear..Try to provide best solutions > > > Thanks & Regards > Shashank " "The best way to escape from a problem is to solve it." > > -- > 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] Convert a Binary tree into spike.
Do a breadth first search on the tree and link all nodes at the same level in the order that you process them --Anurag On Thu, May 13, 2010 at 9:18 AM, vinayan c wrote: > Something like this > 1 > 2 3 > 4 5 6 7 > > > 1 > | > 2->3 > | > 4->5->6->7 > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > 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] Marbles
@Rohit: Can you explain the solution? I was unable to understand why the (n-1) and (k-1) instead of just n and k. Thanks and regards, Anurag Bhatia On Sun, Mar 7, 2010 at 3:33 PM, Anil C R wrote: > yeah my bad :P... > after all the time i struggled with DP :P > Anil > > -- > 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] Find parent/grandparent relationship of nodes in binary tree in O(1) time
@Nirmal: Did you find a solution as yet? On Thu, Jan 28, 2010 at 6:40 PM, Nirmal wrote: > I found this problem in one of the interview form, that it is interesting to > discuss > > Problem : > > There are two nodes given in a tree(not binary tree). Find whether one node > is parent/grand parent of other. > order should be O(1). > > You are allowed to do any amount of preprocessing > > -- > 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] Coding Problems
www.projecteuler.net has some interesting problems. On Tue, Feb 2, 2010 at 6:07 PM, sharad kumar wrote: > www.topcoder.com/tc > www.spoj.pl > > On Tue, Feb 2, 2010 at 4:24 PM, Neeraj Singh <17.neera...@gmail.com> wrote: >> >> Hey fellas, >> >> I need to seek some advice from you all. >> >> I have recently developed strong interest in programming problems. >> So, What is the best place I should start practicing my skills. >> >> It would be great if the effort is rewarding as well. >> >> Thanks in advance. >> >> TY >> -- >> Neeraj >> Ted Turner - "Sports is like a war without the killing." >> >> -- >> 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] missing integers in an unsorted array
Sum of n numbers = n(n+1)/2 Traverse the array and add up all the numbers. Subtract that from the sum of n numbers. --Anurag On Mon, Feb 1, 2010 at 4:24 AM, Banoo wrote: > hi, > can you help me solve the following problem? > > You are given an unsorted list of n-1 distinct integers from the range > 1 to n. Write a linear-time algorithm to find the missing integer. > > > Thanks > > -- > 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] Add 2 long integers with digits represented by linked lists
If that is the representation, then the lists have to be reversed. Otherwise the time goes up exponentially. On Wed, Jan 27, 2010 at 5:19 PM, Algoose Chase wrote: > Condition: > Can we do it keeping the original lists intact ? ie without reversing it. > I mean , No recursion & no Reversing ... is it possible ? > > @kumar : > 15234 is represented as 1->5->2->3->4 > > On Wed, Jan 27, 2010 at 4:09 PM, saurabh gupta wrote: >> >> perhaps you mean, >> reverse each link list O(n+m). >> then sum each node with carryover maintained. >> >> On Wed, Jan 27, 2010 at 11:07 AM, Anurag Bhatia >> wrote: >>> >>> Let us take an example - >>> >>> Num 1 = 123456 >>> Num 2= 1234 >>> Link-1->Link-2->Link-3->Link-4->Link5->Link6 >>> Link-1->Link-2->Link-3->Link-4 >>> >>> Add nodes into linkedlist 1 till either one of the list is not null. >>> Make sure you process the carry in each iteration. >>> >>> >>> --AB >>> >>> >>> On Tue, Jan 26, 2010 at 9:47 PM, Algoose Chase >>> wrote: >>> > conditions: >>> > NO extra memory (@ stack or Heap) at all. No recursion. >>> > >>> > Any body has got any hint about how to get this done ? >>> > >>> > >>> > >>> > -- >>> > 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] Add 2 long integers with digits represented by linked lists
Let us take an example - Num 1 = 123456 Num 2= 1234 Link-1->Link-2->Link-3->Link-4->Link5->Link6 Link-1->Link-2->Link-3->Link-4 Add nodes into linkedlist 1 till either one of the list is not null. Make sure you process the carry in each iteration. --AB On Tue, Jan 26, 2010 at 9:47 PM, Algoose Chase wrote: > conditions: > NO extra memory (@ stack or Heap) at all. No recursion. > > Any body has got any hint about how to get this done ? > > > > -- > 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.