[algogeeks] DE Shaw written test
there is a stock company whose stock prices are known to u for next 365 days. u have to write the code on which day u should buy and sell the stock. U cannot sell a stock until you haven't bought any stock. my approach was to buy the stock when the stock prices are the lowest and sell them when they are the highest. But i think am missing something because this question was for a considerable amount of marks but the solution is too obvious! any thoughts ? -- 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/-/Qw0NRAP_TtwJ. 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] is given number is lucky..?
@daksh paaji kya baat hai thanks for the solution. aap har jagah hai :P On Sat, Aug 4, 2012 at 12:21 AM, Daksh Talwar dakshtal...@gmail.com wrote: maintain a bool array of size of limit of int store true for lucky numbers and then cross check using the function. create the bool array like the one they show in the wiki page -- 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: Microsoft online questions : DLL to bst??
http://www.geeksforgeeks.org/archives/17629 On 2 August 2012 19:50, Daksh Talwar dakshtal...@gmail.com wrote: When asked , try to make the most balanced one . otherwise there are many possible BSTs for a given array/linked list. On Thu, Aug 2, 2012 at 5:05 PM, Umer Farooq the.um...@gmail.com wrote: A LinkedList is by itself is a BST such that one child node of each node is null. Do we need a simple BST or height balanced BST? On Tue, Jul 31, 2012 at 2:39 PM, Ashish Goel ashg...@gmail.com wrote: how would you do convert sorted doubly linked list to bst using same nodes as in DLL Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Sun, Jul 29, 2012 at 10:30 PM, Purani Sekar nagapur...@gmail.comwrote: convert sorted doubly linked list to bst using same nodes as in DLL -- 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. -- Umer -- 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. -- - - - - - - - - - - - - With Regards Daksh Talwar -- 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. -- aviNash -- 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] DE Shaw written test
This can be done in O(n) time complexity and O(1) space complexity using dynamic programming.Consider a situation in which I have been given an array of stock values for N days (in your case N=365) which looks like: int a [ ] = { 5, 10, 4, 6, 7 }; Now,use two variables min (which will keep track of minimum element found upto some index i) and max_profit (keeps track of maximum profit that can be obtained ). int min = a[0]; // initialized to first element int max_profit = 0; //when you buy and sell on same day for ( int i = 1; i n; i++ ){ if ( max_profit (a[i] - min ) ) max_profit = a[i] - min; if ( a[i] min ) min = a[i]; } Finally. I'll have min and max_profit, so if you need to find the buying and selling day you can easily calculate using min and max_profit. Buying day = min; Selling day = min+max_profit; I hope it's clear.Even if something is wrong or difficult to understand you can check this link : http://stackoverflow.com/questions/7086464/interview-question-maximum-single-sell-profit Thanks. On Sun, Aug 5, 2012 at 10:07 AM, harsha harshacoo...@gmail.com wrote: there is a stock company whose stock prices are known to u for next 365 days. u have to write the code on which day u should buy and sell the stock. U cannot sell a stock until you haven't bought any stock. my approach was to buy the stock when the stock prices are the lowest and sell them when they are the highest. But i think am missing something because this question was for a considerable amount of marks but the solution is too obvious! any thoughts ? -- 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/-/Qw0NRAP_TtwJ. 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] DE Shaw written test
@harsha : yes, the problem is if u r finding only min and max value, it might happen that u sell the stock before buying. Ex- int a [ ] = { 5, 10, 4, 6, 7 }; the min value is 4 and max is 10 and 10 comes before 4, means u sell the stock before buying. and i think the sol given by mukul does the same mistake.we need to keep track this case also whether the day(array index) i m buying is not more than the day(array index) we are selling the stock. *correct me if m wrong*. -- 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] Re: DE Shaw written test
@ harsha : consider a case like this : 3 11 1 7 by your algo 1 is the minimum stock price, and you will sell it for 7-1=6 whereas the max prize is 11-3=8, I have code like this : double maxProfit = 0, minBuy = 1000; int minBuyTime = -1, resultBuyTime = -1, resultSellTime = -1; for (int i=0; iN; i++) { //consider selling now double saleProfit = arr[i] - minBuy; if (saleProfit maxProfit) { maxProfit = saleProfit; resultBuyTime = minBuyTime; resultSellTime = arr[i]; } //consider if there's a new minimum buy price if (arr[i] minBuy) { minBuy = arr[i]; minBuyTime = i; } } printf (Buy time: %lf, Sell Time: %lf, Profit: %lf, resultBuyTime, resultSellTime, maxProfit); I hope this would work, also could u elaborate on DeShaw's procedure, was there a separate coding round On Sunday, August 5, 2012 10:07:21 AM UTC+5:30, harsha wrote: there is a stock company whose stock prices are known to u for next 365 days. u have to write the code on which day u should buy and sell the stock. U cannot sell a stock until you haven't bought any stock. my approach was to buy the stock when the stock prices are the lowest and sell them when they are the highest. But i think am missing something because this question was for a considerable amount of marks but the solution is too obvious! any thoughts ? -- 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/-/oFONPkTw7JgJ. 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 question
Given a singly linked list with a random pointer pointing to any node(can be even null). Create a clone of the list. node structure can be : struct node { struct node *next; struct node *random; int value; } The next pointer points to next node in the list while random pointer may point to anywhere. We have to Clone the list. -- best wishes!! Vaibhav -- 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] amazon online test question
Wow.. You got this question... Lucky Fellow so easy.. I remember SISO asking such question long back.. its way below Amazon Standard... Basically they want to make Sure U understand the question.. Implementation is jst a copy of the content of the current SLL Node and rewiring the rest. On Sun, Aug 5, 2012 at 6:39 PM, vaibhav shukla vaibhav200...@gmail.comwrote: Given a singly linked list with a random pointer pointing to any node(can be even null). Create a clone of the list. node structure can be : struct node { struct node *next; struct node *random; int value; } The next pointer points to next node in the list while random pointer may point to anywhere. We have to Clone the list. -- best wishes!! Vaibhav -- 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] DE Shaw written test
Thanks for pointing out the mistake.Though my code will correctly calculate the max_profit but I must keep track of the buying_day.I have made some modification in my code.Hope it works fine now. int min = a[0]; // initialized to first element int max_profit = 0; //when you buy and sell on same day int buying_day = a[0]; for ( int i = 1; i n; i++ ){ if ( max_profit (a[i] - min ) ){ max_profit = a[i] - min; buying_day = min; } if ( a[i] min ) min = a[i]; } Finally. I'll have buying_day and max_profit, so if you need to find the selling day you can easily calculate : Selling day = buying_day+max_profit; Correct me if I'm wrong. On Sun, Aug 5, 2012 at 5:43 PM, Arun Kindra arunkin...@gmail.com wrote: @harsha : yes, the problem is if u r finding only min and max value, it might happen that u sell the stock before buying. Ex- int a [ ] = { 5, 10, 4, 6, 7 }; the min value is 4 and max is 10 and 10 comes before 4, means u sell the stock before buying. and i think the sol given by mukul does the same mistake.we need to keep track this case also whether the day(array index) i m buying is not more than the day(array index) we are selling the stock. *correct me if m wrong*. -- 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] Re: DE Shaw written test
This is a linear time constant space algorithm. Assume the stocks prices are given in an array where index represents the day no . For ex a[365] represents stock price on 365th day of year. Find the min and max element in the array. If the min comes before max, then return the dates- min to buy and max to sell. But if the min comes after max, find the max element that comes after min i.e. maxRight find the min element that comes before max i.e. minLeft Now find the difference (max - minLeft)( maxRight - min) return the dates for which the difference is higher. Code:-- void FindDaytoBuySellStock(int stocks[], int N) // here N = 365 { int minPos = findMinPos(stocks); int maxPos = findMaxPos(stocks); if(minPos maxPos ) { BuyDate = minPos,SellDate = maxPos; } else{ minLeft = find min in array from 0 to maxPos-1 maxRight = find max in array from minPos+1 to N int d1 = max - minLeft; int d2 = maxRight - min; if(d1 = d2 ) {BuyDate = minLeft,SellDate = max; } else{ BuyDate = min ,SellDate = maxRight; } } } -- 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/-/dSJCOIuUuKUJ. 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] Re: coin problem
@Dave , the question clearly says that one group contains 10 heads while the other one contains 10tails. while ur answer gives equal no. of head and tails in each group. On Tuesday, 31 July 2012 17:28:59 UTC+5:30, Dave wrote: @Navin: Divide the coins into two groups of 10, and then flip all of the coins in one of the groups. Suppose group A has x heads and 10 - x tails. Then before you flip them, group B has 10 - x heads and x tails. After you flip them, group B has x heads and 10 - x tails. Dave On Tuesday, July 31, 2012 2:03:09 AM UTC-5, Navin Kumar wrote: You are blindfolded and 20 coins are placed on the table in front of you. Out of them 10 coins have heads facing up and other tails. You are allowed to flip and move the coins. You should divide those coins into two sets such that one set contains 10 heads and other tails. You are allowed to only move or flip the coins -- 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/-/Iz-qgJVHqYMJ. 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] BFS
Can you give proper data structure used to represent graph in your case ? On Wed, Aug 1, 2012 at 9:42 PM, harsha harshacoo...@gmail.com wrote: hello all, i was recently trying to solve a BFS problem where each node is represented by a different arrangement of elements in an array but am unable to come with a data structure to keep track of the visited nodes. generally nodes are different strings so we can just use map and set visited nodes to 1 but what can i use in the above case? -- 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/-/anThAhS9D8sJ. 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, Jalaj Jaiswal Software Engineer, Zynga Inc +91-9019947895 * * FACEBOOK http://www.facebook.com/jalaj.jaiswal89 LINKEDINhttp://www.linkedin.com/profile/view?id=34803280trk=tab_pro -- 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] amazon online test question
yeah... i got that... just shared with algogeeks ;) questions were somewhat easy On Sun, Aug 5, 2012 at 7:25 PM, Prem Krishna Chettri hprem...@gmail.comwrote: Wow.. You got this question... Lucky Fellow so easy.. I remember SISO asking such question long back.. its way below Amazon Standard... Basically they want to make Sure U understand the question.. Implementation is jst a copy of the content of the current SLL Node and rewiring the rest. On Sun, Aug 5, 2012 at 6:39 PM, vaibhav shukla vaibhav200...@gmail.comwrote: Given a singly linked list with a random pointer pointing to any node(can be even null). Create a clone of the list. node structure can be : struct node { struct node *next; struct node *random; int value; } The next pointer points to next node in the list while random pointer may point to anywhere. We have to Clone the list. -- best wishes!! Vaibhav -- 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. -- best wishes!! Vaibhav -- 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] Re: heap insertion
the heap will be Level 1:- 1 Level 2:- 28 Level 3:- 3 4 10 12 Level 4:- 75 Hence 8 will be at level 2. -- 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/-/JSj-e0CWSkgJ. 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] longest continuous sequence
Find the longest subarray which consists of numbers that can be arranged in a continuous sequence. For ex- {4,5,1,5,7,6,8,4,1} output-{5,7,6,8,4}.Find the longest. -- 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/-/MuACHn8S8vUJ. 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] Local Minima in Unsorted Array
this could help although not true for many cases as said above http://ideone.com/w5gjK On Sun, Aug 5, 2012 at 8:40 AM, Ashish Goel ashg...@gmail.com wrote: can you give an example of what do you mean by Local minima? From Dave's example, it looks like the minima of the whole array.. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Aug 3, 2012 at 10:32 PM, shady sinv...@gmail.com wrote: Hi, Can anyone tell how to find local minima in an unsorted array ? Recommended solution : O(log(n)) Shady. -- 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] merging
int merge(int arr[],int n) { int l=0; int j=(n/3); int k=2*(n/3); int *a=(int*)malloc(sizeof(int)*n); for(int i=0;in/3;i++) { a[l++]=arr[i]; a[l++]=arr[j++]; a[l++]=arr[k++]; } for(int i=0;in;i++) arr[i]=a[i]; free(a); } cud be dun be dun recursively also to minimize d space complexity... On Sat, Aug 4, 2012 at 8:20 AM, Navin Kumar algorithm.i...@gmail.comwrote: In given array of elements like [a1,a2,a3,..an,b1,b2,b3,..bn,c**1,c2,c3,...cn] .Write an efficient program to merge them like [a1,b1,c1,a2,b2,c2,...an,bn,cn**]. -- 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/-/gVCyxQV1IhAJ. 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] merging
Actually i wanted to do it inplace. Using extra space it is much easier problem. On Mon, Aug 6, 2012 at 12:27 AM, payal gupta gpt.pa...@gmail.com wrote: int merge(int arr[],int n) { int l=0; int j=(n/3); int k=2*(n/3); int *a=(int*)malloc(sizeof(int)*n); for(int i=0;in/3;i++) { a[l++]=arr[i]; a[l++]=arr[j++]; a[l++]=arr[k++]; } for(int i=0;in;i++) arr[i]=a[i]; free(a); } cud be dun be dun recursively also to minimize d space complexity... On Sat, Aug 4, 2012 at 8:20 AM, Navin Kumar algorithm.i...@gmail.comwrote: In given array of elements like [a1,a2,a3,..an,b1,b2,b3,..bn,c**1,c2,c3,...cn] .Write an efficient program to merge them like [a1,b1,c1,a2,b2,c2,...an,bn,cn**]. -- 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/-/gVCyxQV1IhAJ. 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] merging
Can you care to explain as to how exactly the elements are stored? Is it a vactor of strings?? On Mon, Aug 6, 2012 at 12:32 AM, Navin Kumar algorithm.i...@gmail.comwrote: Actually i wanted to do it inplace. Using extra space it is much easier problem. On Mon, Aug 6, 2012 at 12:27 AM, payal gupta gpt.pa...@gmail.com wrote: int merge(int arr[],int n) { int l=0; int j=(n/3); int k=2*(n/3); int *a=(int*)malloc(sizeof(int)*n); for(int i=0;in/3;i++) { a[l++]=arr[i]; a[l++]=arr[j++]; a[l++]=arr[k++]; } for(int i=0;in;i++) arr[i]=a[i]; free(a); } cud be dun be dun recursively also to minimize d space complexity... On Sat, Aug 4, 2012 at 8:20 AM, Navin Kumar algorithm.i...@gmail.comwrote: In given array of elements like [a1,a2,a3,..an,b1,b2,b3,..bn,c**1,c2,c3,...cn] .Write an efficient program to merge them like [a1,b1,c1,a2,b2,c2,...an,bn,cn**]. -- 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/-/gVCyxQV1IhAJ. 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] merging
vector* On Mon, Aug 6, 2012 at 1:02 AM, adarsh kumar algog...@gmail.com wrote: Can you care to explain as to how exactly the elements are stored? Is it a vactor of strings?? On Mon, Aug 6, 2012 at 12:32 AM, Navin Kumar algorithm.i...@gmail.comwrote: Actually i wanted to do it inplace. Using extra space it is much easier problem. On Mon, Aug 6, 2012 at 12:27 AM, payal gupta gpt.pa...@gmail.com wrote: int merge(int arr[],int n) { int l=0; int j=(n/3); int k=2*(n/3); int *a=(int*)malloc(sizeof(int)*n); for(int i=0;in/3;i++) { a[l++]=arr[i]; a[l++]=arr[j++]; a[l++]=arr[k++]; } for(int i=0;in;i++) arr[i]=a[i]; free(a); } cud be dun be dun recursively also to minimize d space complexity... On Sat, Aug 4, 2012 at 8:20 AM, Navin Kumar algorithm.i...@gmail.comwrote: In given array of elements like [a1,a2,a3,..an,b1,b2,b3,..bn,c**1,c2,c3,...cn] .Write an efficient program to merge them like [a1,b1,c1,a2,b2,c2,...an,bn,cn**]. -- 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/-/gVCyxQV1IhAJ. 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] merging
Cos, if they are stored as a vector of strings like a1, b1, etc. then u can use insertion sort like technique. Insert bi and ci between ai and a(i+1), for i=1,2,3n. This can be done simply by modifyin insertion sort code. Pl let me know in case of any flaw! cos it seems to be so simple this way. On Mon, Aug 6, 2012 at 1:02 AM, adarsh kumar algog...@gmail.com wrote: vector* On Mon, Aug 6, 2012 at 1:02 AM, adarsh kumar algog...@gmail.com wrote: Can you care to explain as to how exactly the elements are stored? Is it a vactor of strings?? On Mon, Aug 6, 2012 at 12:32 AM, Navin Kumar algorithm.i...@gmail.comwrote: Actually i wanted to do it inplace. Using extra space it is much easier problem. On Mon, Aug 6, 2012 at 12:27 AM, payal gupta gpt.pa...@gmail.comwrote: int merge(int arr[],int n) { int l=0; int j=(n/3); int k=2*(n/3); int *a=(int*)malloc(sizeof(int)*n); for(int i=0;in/3;i++) { a[l++]=arr[i]; a[l++]=arr[j++]; a[l++]=arr[k++]; } for(int i=0;in;i++) arr[i]=a[i]; free(a); } cud be dun be dun recursively also to minimize d space complexity... On Sat, Aug 4, 2012 at 8:20 AM, Navin Kumar algorithm.i...@gmail.comwrote: In given array of elements like [a1,a2,a3,..an,b1,b2,b3,..bn,c**1,c2,c3,...cn] .Write an efficient program to merge them like [a1,b1,c1,a2,b2,c2,...an,bn,cn**]. -- 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/-/gVCyxQV1IhAJ. 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] merging
i guess dis shud wrk... void merge(int arr[],int i,int k) { if(i==1) { arr[1]=arr[k]; arr[2]=arr[2*k]; return; } int a=arr[i-1]; int b=arr[2*i-1]; int c=arr[3*i-1]; merge(arr,i-1,n-3); int t=(k-3); arr[t]=a; arr[t+1]=b; arr[t+2]=c; } On Mon, Aug 6, 2012 at 1:05 AM, adarsh kumar algog...@gmail.com wrote: Cos, if they are stored as a vector of strings like a1, b1, etc. then u can use insertion sort like technique. Insert bi and ci between ai and a(i+1), for i=1,2,3n. This can be done simply by modifyin insertion sort code. Pl let me know in case of any flaw! cos it seems to be so simple this way. On Mon, Aug 6, 2012 at 1:02 AM, adarsh kumar algog...@gmail.com wrote: vector* On Mon, Aug 6, 2012 at 1:02 AM, adarsh kumar algog...@gmail.com wrote: Can you care to explain as to how exactly the elements are stored? Is it a vactor of strings?? On Mon, Aug 6, 2012 at 12:32 AM, Navin Kumar algorithm.i...@gmail.comwrote: Actually i wanted to do it inplace. Using extra space it is much easier problem. On Mon, Aug 6, 2012 at 12:27 AM, payal gupta gpt.pa...@gmail.comwrote: int merge(int arr[],int n) { int l=0; int j=(n/3); int k=2*(n/3); int *a=(int*)malloc(sizeof(int)*n); for(int i=0;in/3;i++) { a[l++]=arr[i]; a[l++]=arr[j++]; a[l++]=arr[k++]; } for(int i=0;in;i++) arr[i]=a[i]; free(a); } cud be dun be dun recursively also to minimize d space complexity... On Sat, Aug 4, 2012 at 8:20 AM, Navin Kumar algorithm.i...@gmail.comwrote: In given array of elements like [a1,a2,a3,..an,b1,b2,b3,..bn,c**1,c2,c3,...cn] .Write an efficient program to merge them like [a1,b1,c1,a2,b2,c2,...an,bn,cn**]. -- 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/-/gVCyxQV1IhAJ. 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. -- 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] Re: [Amazon]
@ankush, I think the worst case time complexity will be [ (M+N) * L ] this is beacuse, in the worst case all the 2-d arrays can probably contain the element. Now searching the single 2-D array needs O ( M+N ) But since there can be L such 2-D arrays in the worst case, Wors case TC- O[ (M+N) * L ] -- 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/-/4Iwl3b_WikMJ. 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] Re: general tree into BST
I think a BST can be itself considered as a general tree. In case, we need to convert a general tree to BST :- The approach is :- 1- convert the general tree into a double linked list inplace - O(n) 2- Now apply merge sort on the doubly linked list - O(n) 2- Now convert the doubly linked list to BST using bottom-up approach -O(n) all working codes can be found at www.geeksforgeeks.org -- 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/-/_f5nd0vFmKoJ. 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] BFS
the nodes in the graph are implicit. i start with a vector of integers and depending on the conditions of the question i perform some operations on this initial vector and these new vectors become nodes in my graph too. i can't figure out how to mark these nodes as visited. On Sun, Aug 5, 2012 at 11:48 PM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote: Can you give proper data structure used to represent graph in your case ? On Wed, Aug 1, 2012 at 9:42 PM, harsha harshacoo...@gmail.com wrote: hello all, i was recently trying to solve a BFS problem where each node is represented by a different arrangement of elements in an array but am unable to come with a data structure to keep track of the visited nodes. generally nodes are different strings so we can just use map and set visited nodes to 1 but what can i use in the above case? -- 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/-/anThAhS9D8sJ. 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, Jalaj Jaiswal Software Engineer, Zynga Inc +91-9019947895 * * FACEBOOK http://www.facebook.com/jalaj.jaiswal89 LINKEDINhttp://www.linkedin.com/profile/view?id=34803280trk=tab_pro -- 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] Local Minima in Unsorted Array
hello guys, check this code n tell me if i m worng int localminima(int a[],int start,int end) {int mid; while(startend) { mid=(start+end)/2; if(a[start]a[start+1]) return(1); else if(a[end-1]a[end]) return(1); else if(a[mid]a[mid+1]) end=mid-1; else start=mid+1; } if(startend) return 0; return -1; } On Mon, Aug 6, 2012 at 12:15 AM, payal gupta gpt.pa...@gmail.com wrote: this could help although not true for many cases as said above http://ideone.com/w5gjK On Sun, Aug 5, 2012 at 8:40 AM, Ashish Goel ashg...@gmail.com wrote: can you give an example of what do you mean by Local minima? From Dave's example, it looks like the minima of the whole array.. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Aug 3, 2012 at 10:32 PM, shady sinv...@gmail.com wrote: Hi, Can anyone tell how to find local minima in an unsorted array ? Recommended solution : O(log(n)) Shady. -- 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] merging
http://geeksforgeeks.org/forum/topic/amazon-banglore-online-written-2 Read the solution given by asm. Pretty neat. On Mon, Aug 6, 2012 at 1:05 AM, adarsh kumar algog...@gmail.com wrote: Cos, if they are stored as a vector of strings like a1, b1, etc. then u can use insertion sort like technique. Insert bi and ci between ai and a(i+1), for i=1,2,3n. This can be done simply by modifyin insertion sort code. Pl let me know in case of any flaw! cos it seems to be so simple this way. On Mon, Aug 6, 2012 at 1:02 AM, adarsh kumar algog...@gmail.com wrote: vector* On Mon, Aug 6, 2012 at 1:02 AM, adarsh kumar algog...@gmail.com wrote: Can you care to explain as to how exactly the elements are stored? Is it a vactor of strings?? On Mon, Aug 6, 2012 at 12:32 AM, Navin Kumar algorithm.i...@gmail.comwrote: Actually i wanted to do it inplace. Using extra space it is much easier problem. On Mon, Aug 6, 2012 at 12:27 AM, payal gupta gpt.pa...@gmail.comwrote: int merge(int arr[],int n) { int l=0; int j=(n/3); int k=2*(n/3); int *a=(int*)malloc(sizeof(int)*n); for(int i=0;in/3;i++) { a[l++]=arr[i]; a[l++]=arr[j++]; a[l++]=arr[k++]; } for(int i=0;in;i++) arr[i]=a[i]; free(a); } cud be dun be dun recursively also to minimize d space complexity... On Sat, Aug 4, 2012 at 8:20 AM, Navin Kumar algorithm.i...@gmail.comwrote: In given array of elements like [a1,a2,a3,..an,b1,b2,b3,..bn,c**1,c2,c3,...cn] .Write an efficient program to merge them like [a1,b1,c1,a2,b2,c2,...an,bn,cn**]. -- 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/-/gVCyxQV1IhAJ. 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. -- 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.