Re: [algogeeks] Re: Amazon
Thanks :) On Wed, Jul 20, 2011 at 10:55 AM, SAMM somnath.nit...@gmail.com wrote: This comes from the below n-n/2-n/2^2-..-n/2^k until n/2^k=1 Think from bits prospective -- 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] Solve it
New constraint:- What if the array also contains positive and negative numbers? On Tue, Jul 19, 2011 at 4:36 PM, sagar pareek sagarpar...@gmail.com wrote: ok ok ok thank you all On Tue, Jul 19, 2011 at 4:35 PM, ankit sambyal ankitsamb...@gmail.comwrote: @Sagar: 13 is the correct answer. (6+4+3) -- 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 SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT 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] Microsoft Interview Qn - Looping
Naveen indeed it's not infinite loop but it will print MS 2^31+1 times, right ? :) Change it so that it prints it 20 times. On Wed, Jul 20, 2011 at 7:39 AM, naveen ms naveenms...@gmail.com wrote: excuse me...can any explain y it goes to infinite loop.. with regards naveen -- 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] How to design Elevator Control system ?
I think discussing these question here would be a great idea. There is not such place where we can discuss such type of question( Atleast I don't know)+ It is very commonly asked in interviews. On Wed, Jul 20, 2011 at 1:59 AM, radha krishnan radhakrishnance...@gmail.com wrote: i think we should not use the answer from otherr ppl for these type of questions ! This is design ! we have to think of ur own :P -- 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: amazon
On Thu, Jul 14, 2011 at 10:18 AM, rogu3 manikanta...@gmail.com wrote: hey i got doubt regarding 3rd output, r n't u missing {{}{}} case?? Yes it will be. I guess can assume it safely :) 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/-/GuA-rEq4-kYJ. 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] microsoft ques
The O(N) solution which I can think of. We need to divide the array in subarray's with division point being 0. Now, in those sub arrays, there are two cases: First- even number of -ve numbers, then max product of that subarray will be product of all elements. If it contains odd number, then take the product of sub array and divide it with min( MOD(product from start to first- ve number),( last -ve number till end)) On Wed, Jul 13, 2011 at 10:03 AM, shilpa gupta shilpagupta...@gmail.comwrote: array contain negative numbers also including natural numbers correct it... On Wed, Jul 13, 2011 at 9:43 AM, shilpa gupta shilpagupta...@gmail.comwrote: given an array of natural numbers (+ve, 0, -ve) find the maximum product of continuous elements.efficient( O(nlogn) or better)solution is needed. thanks -- 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. -- shilpa gupta b tech 2nd year computer science and engineering 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] C OUTPUT HELP
*OUTPUT-* 78 6 in this problem my problem is using printf and scanf as variable names.they are functions in the stdio.h then how are they available for variable name ??...generally what happens is that whenever we use some name for the function and then use that name for some variable then compiler gives error then why in this case error is not coming ?? Think it in terms of global and local reference. http://ideone.com/u6bQ *PROBLEM 2.* #includestdio.h main() { int i=1; printf(\n%d %d,i^=1%2,i=1%2); // does it evaluate the final value of i before printing ?? **} *OUTPUT-* 3 3 In gcc what i have observed is that arguments of printf are evaluated from right to left i.e i=1%2 is evaluated before i^=1%2...hence i first becomes 2 then 3 after XOR with 1now output according to me should be 3 1.but what actually is happening is that it us evaluating i and then printing it 3 3.can someone explain why this output is coming ? and the last problem Left to right. Try on ideone. void P(int a,int b){ printf a b;} main(){ int x; P (x++,++x); print x++,++x } *PROBLEM 3.* * * #includestdio.h main() { enum {low='a',high='b'}tag; char try=low; printf(Size=%d,sizeof(tag)); switch (try) { case 'a':printf(aaa);break; case 'b':printf(bbb); case 'c':printf(ccc); } //system(pause); } in this program size of enum comes out to be 4..help me in understanding the size of enum...how it is stored in memory??...does the size of enum depend on number of constant in it ?anyone link regarding that ?? -- 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] c doubt
On Mon, Jul 11, 2011 at 5:54 PM, Piyush Kapoor pkjee2...@gmail.com wrote: Can anybody give a full explanation http://ideone.com/K1QmV On Sat, Jul 9, 2011 at 10:49 PM, sunny agrawal sunny816.i...@gmail.comwrote: try to find out the binary representation of float value 5.2 On Sat, Jul 9, 2011 at 10:46 PM, Sangeeta sangeeta15...@gmail.comwrote: int main(){ int i; float a=5.2; char *ptr; ptr=(char *)a; for(i=0;i=3;i++) printf(%d ,*ptr++); } output: 102 102 -90 64.explain? -- 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. -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- 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,* *Piyush Kapoor,* *CSE-IT-BHU* -- 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] Explanation
There are few bugs in your code. You are going to copy 10 characters in string str1, so the ideal size of str should be 10+1(for null character). Now when u used memcpy, then it perfectly copies initial 10 characters in str1. You can see it in you current output. But when u use %s for printing then it keeps printing untill it encounters NULL character. So, the behavior of this code is unpredictable. U can fix it by declaring char str[11]; and adding NULL character at the end str[11]='\0' http://codepad.org/C69G7Gzz On Sat, Jul 9, 2011 at 12:01 PM, Kamakshii Aggarwal kamakshi...@gmail.comwrote: in my compiler,its giving is rajeev this is string 1 is ra On Fri, Jul 8, 2011 at 11:33 AM, rajeev bharshetty rajeevr...@gmail.comwrote: @Vishal : yes I can use strcpy, But What is the problem with memcpy(). On Fri, Jul 8, 2011 at 11:27 AM, Vishal Thanki vishaltha...@gmail.comwrote: memcpy is usually used to copy data structures other than strings. Use strcpy for copying strings!! On Fri, Jul 8, 2011 at 11:25 AM, Navneet Gupta navneetn...@gmail.com wrote: @Vishal, still the array str1 is also 10 bytes only, I know that memcpy overwrites the null character but not sure then what is the correct approach if i still want to use memcpy. Thoughts? On Fri, Jul 8, 2011 at 10:51 AM, Vishal Thanki vishaltha...@gmail.com wrote: you are overwriting terminating null char!! On Fri, Jul 8, 2011 at 10:23 AM, rShetty rajeevr...@gmail.com wrote: #includestdio.h #includestring.h int main() { char str[]=This is rajeev\n; char str1[10]; memset(str,'0',4); printf(%s,str); memcpy(str1,str,10); printf(\n this is string 1\n); printf(%s\n,str1); return 0; } Output is : is rajeev this is string 1 is ra is rajeev it copies 10 characters from str to str1 so the printing is ra is Ok what abt the repeating result? -- 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. -- Regards, Navneet -- 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. -- Regards, Kamakshi kamakshi...@gmail.com -- 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: String burn,measure time puzle
Yes, these solution are valid. But for them the burning rate of each string must be constant. Each piece of string takes exactly an hour to burn, but the burn rate is not constant Can't we have a string which take 45 minutes to burn till half length. 0-L/2. And 15 min from L/2 to L. On Sat, Jul 9, 2011 at 8:57 PM, Dumanshu duman...@gmail.com wrote: @oppilas: light the first string at both ends and in the middle. So it will burn completely in 15 min as the fire is advancing in 4 ways irrespective of the burn rate. when the first string is completely burnt, light the second string at both ends to get another 30 min. So, overall 45 min. On Jul 9, 5:11 am, oppilas . jatka.oppimi...@gmail.com wrote: You have 2 pieces of string of different, unspecified length, and some matches. Each piece of string takes exactly an hour to burn, but the burn rate is not constant. . The strings have different burn rates, and of course you don't know the rates anyway. Using only the matches and the strings, measure 45 minutes. I have thought a lot but unable to find a solution for this problem. Can someone please try 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] Re: String burn,measure time puzle
Sorry, should have done it on paper properly!! Thanks! PS: below is the mail which I was about to write thinking that total time would not be 30 minutes if we burn it from both ends. Ok Suppose the length is 60meters. For 0-L/2 we have burn rate of 2/3m per minute. So, total time L/2/(2/3)= 45minutes. And for L/2 to L, we have burn rate of 2m per min. So, Time for burning 30-60 meters is 15 minute. Suppose, we light up both the ends. Then After 15 minutes, L/2-L portion will be completely burn. And For 0-L/2 portion, we would have burn total 2/3*15= 10meters. Now, You are left with 10-30 (i.e total of 20 meter string) and it is burning at both ends after 15 minutes. So, remaining string will burn in (20)/(2*2/3) time i.e 15 minutes. Shit :\ On Sun, Jul 10, 2011 at 1:02 AM, Dumanshu duman...@gmail.com wrote: The above posted solution is independent of the burning rate. I am not counting the minutes using the half burnt string. Instead, the fire is running and when the whole string is burnt, I am using the time. Say u light up a string from both ends, then irrespective of burn rate it should give 30 min. Because we have the choice to lit the string from either end and it burns completely in 1 hour. On Jul 9, 10:09 pm, oppilas . jatka.oppimi...@gmail.com wrote: Yes, these solution are valid. But for them the burning rate of each string must be constant. Each piece of string takes exactly an hour to burn, but the burn rate is not constant Can't we have a string which take 45 minutes to burn till half length. 0-L/2. And 15 min from L/2 to L. On Sat, Jul 9, 2011 at 8:57 PM, Dumanshu duman...@gmail.com wrote: @oppilas: light the first string at both ends and in the middle. So it will burn completely in 15 min as the fire is advancing in 4 ways irrespective of the burn rate. when the first string is completely burnt, light the second string at both ends to get another 30 min. So, overall 45 min. On Jul 9, 5:11 am, oppilas . jatka.oppimi...@gmail.com wrote: You have 2 pieces of string of different, unspecified length, and some matches. Each piece of string takes exactly an hour to burn, but the burn rate is not constant. . The strings have different burn rates, and of course you don't know the rates anyway. Using only the matches and the strings, measure 45 minutes. I have thought a lot but unable to find a solution for this problem. Can someone please try 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. -- 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: String burn,measure time puzle
light the first string at both ends and in the middle. So it will burn completely in 15 min as the fire is advancing in 4 ways irrespective of the burn rate. If we do the similar analysis for 15 min, I think we won't be able to do so!, Again if the length is of 60min. For 0-30 min, the burn rate is 2/3m/minutes and for 30-60 it's 2m/minutes. If I burn it at 0, 30,60m position, then 30-60 meter part will be burnt in 7.5 minutes only. But 0-30 meter part will take 30/(4/3) i.e = 22.5 minutes. So, the complete string will burn in 22.5 minutes not 15. On Sun, Jul 10, 2011 at 1:26 AM, oppilas . jatka.oppimi...@gmail.comwrote: Sorry, should have done it on paper properly!! Thanks! PS: below is the mail which I was about to write thinking that total time would not be 30 minutes if we burn it from both ends. Ok Suppose the length is 60meters. For 0-L/2 we have burn rate of 2/3m per minute. So, total time L/2/(2/3)= 45minutes. And for L/2 to L, we have burn rate of 2m per min. So, Time for burning 30-60 meters is 15 minute. Suppose, we light up both the ends. Then After 15 minutes, L/2-L portion will be completely burn. And For 0-L/2 portion, we would have burn total 2/3*15= 10meters. Now, You are left with 10-30 (i.e total of 20 meter string) and it is burning at both ends after 15 minutes. So, remaining string will burn in (20)/(2*2/3) time i.e 15 minutes. Shit :\ On Sun, Jul 10, 2011 at 1:02 AM, Dumanshu duman...@gmail.com wrote: The above posted solution is independent of the burning rate. I am not counting the minutes using the half burnt string. Instead, the fire is running and when the whole string is burnt, I am using the time. Say u light up a string from both ends, then irrespective of burn rate it should give 30 min. Because we have the choice to lit the string from either end and it burns completely in 1 hour. On Jul 9, 10:09 pm, oppilas . jatka.oppimi...@gmail.com wrote: Yes, these solution are valid. But for them the burning rate of each string must be constant. Each piece of string takes exactly an hour to burn, but the burn rate is not constant Can't we have a string which take 45 minutes to burn till half length. 0-L/2. And 15 min from L/2 to L. On Sat, Jul 9, 2011 at 8:57 PM, Dumanshu duman...@gmail.com wrote: @oppilas: light the first string at both ends and in the middle. So it will burn completely in 15 min as the fire is advancing in 4 ways irrespective of the burn rate. when the first string is completely burnt, light the second string at both ends to get another 30 min. So, overall 45 min. On Jul 9, 5:11 am, oppilas . jatka.oppimi...@gmail.com wrote: You have 2 pieces of string of different, unspecified length, and some matches. Each piece of string takes exactly an hour to burn, but the burn rate is not constant. . The strings have different burn rates, and of course you don't know the rates anyway. Using only the matches and the strings, measure 45 minutes. I have thought a lot but unable to find a solution for this problem. Can someone please try 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. -- 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: String burn,measure time puzle
The solution of second puzzle is correct and for the first one I won't argue now :P.(sorry ) On 7/10/11, Dumanshu duman...@gmail.com wrote: the string burns in an hour if lit from one end and string burns in 30 min if lit from both ends. This fact is based on - light up the string from either end it burns in 60 min. now heres the solution: Light up the first string from both ends and the second string from one end at the same time. When the first string burns up completely, light up the already burning second string from the other end. When the second string burns up, we have 45 min irrespective of the burn rate. Even if you assume some different values of burn rate to make the overall burn rate variable, you would get 45 min only. On Jul 9, 5:11 am, oppilas . jatka.oppimi...@gmail.com wrote: You have 2 pieces of string of different, unspecified length, and some matches. Each piece of string takes exactly an hour to burn, but the burn rate is not constant. . The strings have different burn rates, and of course you don't know the rates anyway. Using only the matches and the strings, measure 45 minutes. I have thought a lot but unable to find a solution for this problem. Can someone please try 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] array or matrix problems...anyone?
What method did you used to multiply it efficiently? Any link for the same? On Fri, Jul 8, 2011 at 10:05 PM, Sriganesh Krishnan 2448...@gmail.comwrote: ya...did that...anything else! you know...like interview questions and stuff? On Fri, Jul 8, 2011 at 10:01 PM, shady sinv...@gmail.com wrote: two* On Fri, Jul 8, 2011 at 10:00 PM, shady sinv...@gmail.com wrote: try multiplying too matrices efficiently seems simple, doesn't it :P On Fri, Jul 8, 2011 at 9:40 PM, Sriganesh Krishnan 2448...@gmail.comwrote: can anybody suggest some good array or matrix related problems! -- 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] String burn,measure time puzle
You have 2 pieces of string of different, unspecified length, and some matches. Each piece of string takes exactly an hour to burn, but the burn rate is not constant. . The strings have different burn rates, and of course you don't know the rates anyway. Using only the matches and the strings, measure 45 minutes. I have thought a lot but unable to find a solution for this problem. Can someone please try 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.
Re: [algogeeks] Re: String burn,measure time puzle
Dave, Thanks for the reply but this solution is only valid when the burn rate is constant. On Sat, Jul 9, 2011 at 9:11 AM, Dave dave_and_da...@juno.com wrote: Light the first string at both ends and the second string at one end. When the first string burns out, 30 minutes will have transpired, and 30 minutes's worth of the second string will remain. Light the second end of the second string. It will burn out in 15 more minutes., making a total of 45 minutes. Dave On Jul 8, 7:11 pm, oppilas . jatka.oppimi...@gmail.com wrote: You have 2 pieces of string of different, unspecified length, and some matches. Each piece of string takes exactly an hour to burn, but the burn rate is not constant. . The strings have different burn rates, and of course you don't know the rates anyway. Using only the matches and the strings, measure 45 minutes. I have thought a lot but unable to find a solution for this problem. Can someone please try 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] Re: Amazon
step:- 1) sort the array 2) remove the smallest and largest element from arary. keep the smallest elemnt in seperate queue(result) 3) repeat the above untill the array is empty or it contains only it contains only one element 4) put the last element also in the queue (result) eg:-for ur example sorted array wl be 2,3,5,,8,,10 result=empty new sorted array=3,5,8 result=2 After this step, according to your second step, you will insert 3 in queue first. Why have u inserted 5 here? new sorted array=5 result 2,5 as it contains only 1 element so result=2,5,3 -- 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] NVIDIA Q
Ok. So for differentiating objects, we have size 1. What will be size of following class:- class A{ int z; }; How does different objects gets differentiated in above case? On Wed, Jul 6, 2011 at 2:24 PM, durgaprasad k durga...@gmail.com wrote: The size will be 1 byte as there is nothing to look into the object. And it is 1 instead of zero because two objects of the class will have different addresses by assigning each object size 1. Regards, Durga On Wed, Jul 6, 2011 at 2:11 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: What is the size of an object of a class with no members in it?? -- *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. -- 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: VIRTUAL INHERITANCE
@T3rminal Then how would you explain size of Z in case of normal inheritance( sizeof(Z)=16 On Mon, Jul 4, 2011 at 4:08 AM, T3rminal piyush@gmail.com wrote: @abc abc 4th class= two ints from X and Y classes + one int from base class( as this class is shared ) + 2 virtual pointers of X and Y classes. According to your logic it should be 12 On Jul 3, 2:24 pm, abc abc may.i.answ...@gmail.com wrote: In the second case , the size of vptr will be added to each and every object . 1st class = one int :4 2nd class = one int +one int from base + vptr =12 3rd class = one int + one int from base + vptr =12 4th class =one int from each base class + one int from each of the grand parent +one vptr =20 On Sun, Jul 3, 2011 at 2:43 PM, himanshu kansal himanshukansal...@gmail.com wrote: class Base { public: int a; }; class X: public Base { public: int x; }; class Y: public Base { public: int y; }; class Z:public X,public Y { }; int main() {coutsizeof(Base)endl; cout sizeof(X) endl; cout sizeof(Y) endl; cout sizeof(Z) endl; } o/p is 4 8 8 16... which is absolutely fine. but the problem arises here class Base { public: int a; }; class X:virtual public Base { public: int x; }; class Y:virtual public Base { public: int y; }; class Z:public X,public Y { }; int main() {coutsizeof(Base)endl; cout sizeof(X) endl; cout sizeof(Y) endl; cout sizeof(Z) endl; } o/p is 4 12 12 20 why the size is 12 and 20 for x and Zdoes this is because that some sort of VPTR IS maintained in the classif yes then then what does that points to PS:HERE.i am talking about virtual inheritanceNOT ABOUT VIRTUAL FUNCTIONS... -- 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] Complexity QuickSort
If u could find the (n/4)th element of an array in O(n) time, then what is the worst time complexity of quick sort algo if this algo is used to decide the pivot element. -- 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] find output
On Mon, Jul 4, 2011 at 3:54 PM, amit the cool amitthecoo...@gmail.comwrote: main() { int i=0; while(+(+i--)!=0) Here the value passed of i is 0 only. So the next statement does not execute. But after using, I gets decremented to -1 i-=i++; printf(%d,i); } output sud be 1 bt it is -1; why?? -- 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] RMQ doubt.
For finding maximum in a given range for an array , we need to construct a seg tree of hight log(n). So, for n queries out time complexity will be O(nlogn). Now, if out query window size is known before hand, suppose j-i==K, how can I reduce the complexity to (nlogK for finding an minimum for a given range.)? I am unable to code it actually. Can anyone please help. PS: I want to solve it using RMQ only. So please reply considering that. -- 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] RMQ doubt.
Sunny yes.. I want to implement RMQ solution of it in O(nlogk) not O(nlogn). On Fri, Jul 1, 2011 at 4:38 PM, sunny agrawal sunny816.i...@gmail.comwrote: is J-I = K for all queries? On Fri, Jul 1, 2011 at 4:08 PM, oppilas . jatka.oppimi...@gmail.comwrote: For finding maximum in a given range for an array , we need to construct a seg tree of hight log(n). So, for n queries out time complexity will be O(nlogn). Now, if out query window size is known before hand, suppose j-i==K, how can I reduce the complexity to (nlogK for finding an minimum for a given range.)? I am unable to code it actually. Can anyone please help. PS: I want to solve it using RMQ only. So please reply considering that. -- 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. -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- 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] Constructing a Binary Search Tree from Post Order traversal-Possible or not
Is it possible to create a binary search tree (not binary tree) from post order traversal only? If give, how and if not please give reason/counter examples. -- 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: Constructing a Binary Search Tree from Post Order traversal-Possible or not
I am unable to find a test case where this particular approach fails( I hardly thinks it's correct but anyway here it is). We make the last element the root of the BST. And keep inserting each element one by one just like normal binary tree insertion. This will take O(n^2) time in worst case( when the tree is only leftist or rightist). For a balance tree it will be T(nLogn). On Thu, Jun 30, 2011 at 7:22 PM, sunny agrawal sunny816.i...@gmail.comwrote: it can be done without sorting(Finding any other traversal) Do it recursively, last element of the traversal will be head, and now if you will see in the traversal left part of the traversal will be its LST and Right will be RST (except Head) only thing you need to find will be the index of the element which divides the traversal into LST and RST. this index can be find very easily beacause all elements of LST are less than root value. On Thu, Jun 30, 2011 at 7:16 PM, Nishant mittal.nishan...@gmail.comwrote: if BST contains integers then sort the postorder traversal which will give you inorder traversal... On Jun 30, 6:27 pm, oppilas . jatka.oppimi...@gmail.com wrote: Is it possible to create a binary search tree (not binary tree) from post order traversal only? If give, how and if not please give reason/counter examples. -- 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. -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- 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] Amazon telephonic question
push(), pop() method as stack, and also has a getMinElement(). Require that getMinElement() is constant time but push()/pop() do not have to be constant time at first. Then for improvement, these three methods are all required to be constant time Define node as struct node{ int data; int curr_min; } void push(int ele){ new node-data= ele; if( ele top-curr_min) new_node- curr_min=ele; else new_node-curr_min= top-curr_min; } Try to simulate it on paper and think now whether push,pop,getMin are O(1) or not. On Wed, Jun 29, 2011 at 12:14 PM, ankit sambyal ankitsamb...@gmail.comwrote: @juver++ : I don't think it will work in O(1) time. Plz post ur algo. I may have misunderstood u !!! On Tue, Jun 28, 2011 at 11:37 PM, juver++ avpostni...@gmail.com wrote: @samby There is no need to use any other data structures but only stack. Each of its nodes is a pair of a data and minimal element below the current node. Then all updates are done in constant time. -- 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/-/XQDUXzPp31oJ. 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] query
Piyush the original code has double apostrophe( ' ) instead of inverted comma's. http://ideone.com/zPpGA On Wed, Jun 29, 2011 at 5:30 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: Its working fine.. On Wed, Jun 29, 2011 at 5:26 PM, sunny agrawal sunny816.i...@gmail.comwrote: the error is in quotes, just rewrite them On Wed, Jun 29, 2011 at 5:24 PM, Anika Jain anika.jai...@gmail.comwrote: hey, printf(%d ya %u in both same error cming.. On Wed, Jun 29, 2011 at 5:10 PM, sunny agrawal sunny816.i...@gmail.comwrote: Because u copied the code i think :P try writing printf statement yourself again :) On Wed, Jun 29, 2011 at 5:05 PM, Anika Jain anika.jai...@gmail.comwrote: int main() { int I =10, j=2; int *ip = I ,*jp =j; int k = *ip/ *jp; printf(“%u”,k); return 0; } in this code error is coming why?? -- 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. -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- 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. -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- 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] query
I have just copied ans pasted the code of OP. And changed . http://codepad.org/rBnx7z8V On Wed, Jun 29, 2011 at 8:17 PM, udit sharma sharmaudit...@gmail.comwrote: @Vaibhav: Sunny is also right bcz if u jst copy n paste d above code with (/ *jp) it'll show an error... And the error is in printf statement. jst cut it from the program n thn write it again.. It'll wrk properly -- 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] Amazon - ispasswordvalid() implementation
Why are we thinking of suffix tree in this case. Does not make sense. It the password is valid then it is of length between 5-12 only. Simple brute force approach will give decent time enough + we will not waste necessary memory and large line of code. On Wed, Jun 29, 2011 at 10:38 PM, Swathi chukka.swa...@gmail.com wrote: Please provide the psuedo code for suffix array or suffix trees which does this.. I got this question in amazon online test... We need to write code, compile and test in amazon online test.. On Wed, Jun 29, 2011 at 10:36 PM, rajat ahuja catch.rajatah...@gmail.comwrote: i think we need to form suffix array of the given string with one extra information tht is frm which index we are considerin suffix then sort those uffixe pointres after tht single scan wud do the job thanks rajat ahuja On Wed, Jun 29, 2011 at 10:23 PM, Swathi chukka.swa...@gmail.com wrote: Write the implementation of isPasswordValid() function which return true if the following conditions matches 1) If password length is between 5 to 12 characters 2) It should be alpha numerics 3) There should not be any consecutive substrings ex - ab12abc [valid as there are no consecutive substrings] ex - ab12abcabc [not valid as abc is consecutive substring]. Can someone provide the pseudo code with the logic.. Thanks, Swathi -- 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] Amazon - ispasswordvalid() implementation
http://ideone.com/YlGCC On Wed, Jun 29, 2011 at 10:47 PM, Swathi chukka.swa...@gmail.com wrote: If you have any strong solution then write the pseudo code and explain your logic... please dont simply write like this.. it saves lot of time... code and explain On Wed, Jun 29, 2011 at 10:45 PM, oppilas . jatka.oppimi...@gmail.comwrote: Why are we thinking of suffix tree in this case. Does not make sense. It the password is valid then it is of length between 5-12 only. Simple brute force approach will give decent time enough + we will not waste necessary memory and large line of code. On Wed, Jun 29, 2011 at 10:38 PM, Swathi chukka.swa...@gmail.com wrote: Please provide the psuedo code for suffix array or suffix trees which does this.. I got this question in amazon online test... We need to write code, compile and test in amazon online test.. On Wed, Jun 29, 2011 at 10:36 PM, rajat ahuja catch.rajatah...@gmail.com wrote: i think we need to form suffix array of the given string with one extra information tht is frm which index we are considerin suffix then sort those uffixe pointres after tht single scan wud do the job thanks rajat ahuja On Wed, Jun 29, 2011 at 10:23 PM, Swathi chukka.swa...@gmail.comwrote: Write the implementation of isPasswordValid() function which return true if the following conditions matches 1) If password length is between 5 to 12 characters 2) It should be alpha numerics 3) There should not be any consecutive substrings ex - ab12abc [valid as there are no consecutive substrings] ex - ab12abcabc [not valid as abc is consecutive substring]. Can someone provide the pseudo code with the logic.. Thanks, Swathi -- 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. -- 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] Amazon - ispasswordvalid() implementation
What I wanted to say that, it's a trivial question for algorithmic point of view. You could have just implemented a normal function without worrying about complexity because the constraints were quite low. I have not tested it for all corner cases. If it fails somewhere then give the test case. I will try to fix it. Cheers :) On Wed, Jun 29, 2011 at 11:35 PM, oppilas . jatka.oppimi...@gmail.comwrote: http://ideone.com/YlGCC On Wed, Jun 29, 2011 at 10:47 PM, Swathi chukka.swa...@gmail.com wrote: If you have any strong solution then write the pseudo code and explain your logic... please dont simply write like this.. it saves lot of time... code and explain On Wed, Jun 29, 2011 at 10:45 PM, oppilas . jatka.oppimi...@gmail.comwrote: Why are we thinking of suffix tree in this case. Does not make sense. It the password is valid then it is of length between 5-12 only. Simple brute force approach will give decent time enough + we will not waste necessary memory and large line of code. On Wed, Jun 29, 2011 at 10:38 PM, Swathi chukka.swa...@gmail.comwrote: Please provide the psuedo code for suffix array or suffix trees which does this.. I got this question in amazon online test... We need to write code, compile and test in amazon online test.. On Wed, Jun 29, 2011 at 10:36 PM, rajat ahuja catch.rajatah...@gmail.com wrote: i think we need to form suffix array of the given string with one extra information tht is frm which index we are considerin suffix then sort those uffixe pointres after tht single scan wud do the job thanks rajat ahuja On Wed, Jun 29, 2011 at 10:23 PM, Swathi chukka.swa...@gmail.comwrote: Write the implementation of isPasswordValid() function which return true if the following conditions matches 1) If password length is between 5 to 12 characters 2) It should be alpha numerics 3) There should not be any consecutive substrings ex - ab12abc [valid as there are no consecutive substrings] ex - ab12abcabc [not valid as abc is consecutive substring]. Can someone provide the pseudo code with the logic.. Thanks, Swathi -- 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. -- 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] Amazon - ispasswordvalid() implementation
Sorry, didn't noticed that it was hard coded :) On Thu, Jun 30, 2011 at 12:13 AM, oppilas . jatka.oppimi...@gmail.comwrote: You code returns 1 for - input: abab1abab1 output: 1 - input: abababab1abab: 1 On Thu, Jun 30, 2011 at 12:04 AM, Anantha Krishnan ananthakrishnan@gmail.com wrote: http://ideone.com/oEfLE On Thu, Jun 30, 2011 at 12:04 AM, Anantha Krishnan ananthakrishnan@gmail.com wrote: I wish to say that we should not use any inbuilt functions. On Wed, Jun 29, 2011 at 11:43 PM, oppilas . jatka.oppimi...@gmail.comwrote: What I wanted to say that, it's a trivial question for algorithmic point of view. You could have just implemented a normal function without worrying about complexity because the constraints were quite low. I have not tested it for all corner cases. If it fails somewhere then give the test case. I will try to fix it. Cheers :) On Wed, Jun 29, 2011 at 11:35 PM, oppilas . jatka.oppimi...@gmail.comwrote: http://ideone.com/YlGCC On Wed, Jun 29, 2011 at 10:47 PM, Swathi chukka.swa...@gmail.comwrote: If you have any strong solution then write the pseudo code and explain your logic... please dont simply write like this.. it saves lot of time... code and explain On Wed, Jun 29, 2011 at 10:45 PM, oppilas . jatka.oppimi...@gmail.com wrote: Why are we thinking of suffix tree in this case. Does not make sense. It the password is valid then it is of length between 5-12 only. Simple brute force approach will give decent time enough + we will not waste necessary memory and large line of code. On Wed, Jun 29, 2011 at 10:38 PM, Swathi chukka.swa...@gmail.comwrote: Please provide the psuedo code for suffix array or suffix trees which does this.. I got this question in amazon online test... We need to write code, compile and test in amazon online test.. On Wed, Jun 29, 2011 at 10:36 PM, rajat ahuja catch.rajatah...@gmail.com wrote: i think we need to form suffix array of the given string with one extra information tht is frm which index we are considerin suffix then sort those uffixe pointres after tht single scan wud do the job thanks rajat ahuja On Wed, Jun 29, 2011 at 10:23 PM, Swathi chukka.swa...@gmail.comwrote: Write the implementation of isPasswordValid() function which return true if the following conditions matches 1) If password length is between 5 to 12 characters 2) It should be alpha numerics 3) There should not be any consecutive substrings ex - ab12abc [valid as there are no consecutive substrings] ex - ab12abcabc [not valid as abc is consecutive substring]. Can someone provide the pseudo code with the logic.. Thanks, Swathi -- 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. -- 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
Re: [algogeeks] Re: Product of N numbers - with Constraints
Anand, The code mentioned on your blog is wrong. http://codepad.org/n7YLkqaR On Mon, Jun 27, 2011 at 5:28 AM, Anand anandut2...@gmail.com wrote: http://anandtechblog.blogspot.com/2010/09/given-array-of-numbers-replace-each.html On Sun, Jun 26, 2011 at 10:12 AM, ross jagadish1...@gmail.com wrote: @Dave: Very good solution.. I had thought an idea of using separate arrays to store next and previous products. And multiplying the elements of the 2 arrays to give B. The solution given by you satisfies ALL constraints inplace :) @sameer: Your solution is not O(1) in space dude..Dave's solution is good. On Jun 26, 9:47 pm, Ashish Goel ashg...@gmail.com wrote: this is goog question Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Sun, Jun 26, 2011 at 10:04 PM, Dave dave_and_da...@juno.com wrote: @Ross: This satisfies your constraints... B[0] = 1; for( i = 1 ; i N ; ++i ) B[i] = B[i-1] * A[i-1]; int x = 1; for( i = N-1 ; i 0 ; --i ) { x *= A[i]; B[i-1] *= x; } Dave On Jun 26, 11:08 am, ross jagadish1...@gmail.com wrote: Given an array A , of N integers ( In no particular order), fill up an auxilary array B such that B[i] contains the product of all elements in A other than A[i]. Constraints: O(n) Time, Can this be done with O(1) space? Division is *not* allowed . eg: A 1 2 3 4 5 B 120 60 40 30 24 -- 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] Mouse Beer Puzzle
There are 6 beer bottle nd one is **not** poisoned. we have mice who will die within 14 hrs after drinkin poisned beer. In 24 hrs we have to find *nonpoisonous *beer bottle. How many no of mice we require to find out non poisoned bottle.? -- 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] Mouse Beer Puzzle
Manish can you explain how? Please read the question carefully and explain accordingly. On Tue, Jun 28, 2011 at 3:40 PM, Manish Pathak pathak@gmail.com wrote: answer is 3 -- Thanks and Regards, Manish Pathak ** TimesJobs.com -- 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] Mouse Beer Puzzle
Andres yes, I also think so. We will end up using 5 mice. On Tue, Jun 28, 2011 at 3:54 PM, Anders Ma xuejiao...@gmail.com wrote: I think the answer is 5. To know which one is poisonous, you have to use one mouse. How to use 3 mice achieve this goal? If all the 3 mice drink the poisonous beer, they will die first, how does the test go on? although you can let one mouse drink several beer in different time table, but if the first drinking beer is poisonous, the mouse will die, and all the other beer the mouse just drunk can not prove if poisonous. If I am wrong, please tell me , thanks! On Tue, Jun 28, 2011 at 6:10 PM, Manish Pathak pathak@gmail.com wrote: answer is 3 -- Thanks and Regards, Manish Pathak TimesJobs.com -- 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 Anders -- 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: O(n) Time is the problem. ..
Suppose after first iteration, I iterate through whole array XORring+(1..N) the last bit and I get 1. Now, for making sure I don't need process undesirable numbers with last bit '0', I will need to use sum bool array of size N bits to discard those numbers or I can do it without using it? Explanation for others. Suppose the given array is - A[6]={ 0,1,2,3,5,6} // Missing number is 4. - Now, XOR of (1^2^3^^4^5^6)=7(111).==TEMP - Now, I will get last bit of the all array elements and XOR it with last bit of TEMP i.e 1, so, 1^A[0][0]^A[1][0]...A[5[0] gives us 0. ( Last bit of missing number is 0. Correct as 4 was missing). - Now, I if I will discard all those numbers with last bit 0, I will be left with (1,3,5) - Now, 2last last bit of TEMP is 1. And of (1,3,5) is (0,1,0) receptively. So, I will XOR all these and I will get 0' - Again after ignoring numbers with 0 as we are only left with 3. Now xor 3rd from last bit with, we get 1. - So, the Desired number is 100 i.e 4. Here, as Fetching one bit takes constant time, For the first time we only fetched O(N) bytes. Next time we fetched O(N/2) and so on we will have to fetch O(N/4)+O(N/8). bites. So, overall time complexity is O(N). It would have been O(KN) where K is the number of bites in a integer only we would have fetched all the bites at least once. ~ Oppilas On Mon, Jun 27, 2011 at 8:38 AM, Dave dave_and_da...@juno.com wrote: @Sanket: Yes. That is the first O(n) in my previous posting http://groups.google.com/group/algogeeks/msg/cd32a2276c6a2d22. Dave On Jun 26, 6:55 pm, Sanket vasa.san...@gmail.com wrote: Thanks Dave. Won't Also, calculate the xor of the low order bits of the data require you to access each value in the array once? Or am I not understanding what you meant? On Jun 26, 6:50 pm, Dave dave_and_da...@juno.com wrote: @Sanket: Sure. 0^1^2^...^N is periodic with period 4. Thus, only the last two bits of N need be considered, i.e., N 3. You could index into an array A[] = {0,1,1,0}, or note that 0110 in binary is 6, so the expression can be evaluated with bit operations by (6 (N 3)) 1. Also, calculate the xor of the low order bits of the data. If the two quantities agree, you know that the low order bit of the missing data is 0, else it is 1. Dave On Jun 26, 5:23 pm, Sanket vasa.san...@gmail.com wrote: Dave - Can you elaborate on how you can do this - you can determine whether the low order bit of the missing number is 0 or 1 On Jun 26, 2:32 pm, Kamakshii Aggarwal kamakshi...@gmail.com wrote: thanks dave.. On 6/26/11, Dave dave_and_da...@juno.com wrote: @Kamakshii: In O(n), you can determine whether the low order bit of the missing number is 0 or 1. You can eliminate the approximately n/2 numbers that do not have this low order bit. Then, in O(n/2), you can determine the next-to-low order bit. Etc. O(n) + O(n/2) + O(n/4) + ... = O(n). Dave On Jun 26, 2:41 am, Kamakshii Aggarwal kamakshi...@gmail.com wrote: @dave:can u please give the divide and conquer solution On 6/26/11, Kamakshii Aggarwal kamakshi...@gmail.com wrote: @aditya:it is given in the question that u cannot access the entire element in single operaion..therefore both your above solution do not hold for this question. On 6/25/11, sunny agrawal sunny816.i...@gmail.com wrote: @Dave yes u r right that integers means it can be big integers too. generally when we talk about integers, they are 32 bit integers in Programing/Algorithm Questions so i was assuming that here and about my solution - yes it will be O(nlgn) or O(nw) not acceptable for given Q :( and yes a Divide and Conquer solution can do it in O(n). I just came to know ..thanks i little bit similer to my approachNice One On Sat, Jun 25, 2011 at 9:15 PM, Dave dave_and_da...@juno.com wrote: @Sunny. You are reading too much into that. There is no mention that the data are 32-bit integers. Perhaps they are big integers. What we know is that the data are not characters, real numbers, rational numbers, floating point, etc. Your algorithm is O(n*w), where w is the word size. As I said, a divide-and-conquer algorithm can find the missing number in O(n). Furthermore, this is independent of the word size. Dave On Jun 24, 11:44 pm, sunny agrawal sunny816.i...@gmail.com wrote: @Dave it is given in Question that elements of array are integer On Sat, Jun 25, 2011 at 7:17 AM, Dave dave_and_da...@juno.com wrote: @Sunny: What makes you think that the integers are 32 bits in length. Remember that O(.) notation applies as n -- infinity. Thus, O(n log
[algogeeks] Printing unique rows.
Given a binary matrix of N X N of integers , you need to return only unique rows of binary arrays eg: 0 1 0 0 1 1 0 1 1 0 0 1 0 0 1 1 1 1 0 0 ans: 0 1 0 0 1 1 0 1 1 0 1 1 1 0 0 -- 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: strings
anonymous see this http://ideone.com/TuNbS Can anyone tell me why gcc complier giving this warning prog.c:8: warning: implicit declaration of function ‘strlen’ On 6/26/11, anonymous procrastination opamp1...@gmail.com wrote: So finally what will be the solution? Harshal's solution doesn't print the characters in the order of appearance in the orignal array as nishant righly pointed out. -- 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] char *arr and char arr[]
I was reading about how char *arr is different from char arr[]. Now, as in char *arr=Pilani, arr stores the base address of the memory block reserved for Pilani. How, can I change the any character at that particular memory block? arr[0] ='T' gives error. #includeiostream using namespace std; int main(){ char *p=Pilani; // p[0]='K'// does not work. // *(p[0])='s'; //does not work; coutp[0] (void *)p \n; return 0; } -- 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: char *arr and char arr[]
Thanks all :). On 6/25/11, Anantha Krishnan ananthakrishnan@gmail.com wrote: When we declare *char *str=hello;* this hello will be stored in the read-only memory i.e *TEXT Segment*. so when we try to write the read-only memory by **str='w';* it will throw *Segmentation fault*. Obviously we must allocate some memory in heap to modify it like: *char *str=(char *)malloc(1024);* Thanks Regards, Anantha Krishnan On Sat, Jun 25, 2011 at 2:16 PM, Adarsh s.adars...@gmail.com wrote: char array[] = hello; char *pointer = hello; array is an array, enough to store sequence of characters and '\0' array will always refer to same storage. Here, pointer is initialized to point to a string constant, pointer may be modified, but you cannot chage string contents -- 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] Re: Sort - Consecutive Array in O(n)
Divye Thanks for the link. Quoting the top answer from there. Under the assumption numbers less than one are not allowed and there are no duplicates, there is a simple summation identity for this - the sum of numbers from 1 to m in increments of 1 is (m * (m + 1)) / 2. You can then sum the array and use this identity. You can find out if there is a dupe under the above guarantees, plus the guarantee no number is above m or less than n (which can be checked in O(N)) The idea in pseudo-code: 0) Start at N = 0 1) Take the N-th element in the list. 2) If it is not in the right place if the list had been sorted, check where it should be. 3) If the place where it should be already has the same number, you have a dupe - RETURN TRUE 4) Otherwise, swap the numbers (to put the first number in the right place). 5) With the number you just swapped with, is it in the right place? 6) If no, go back to step two. 7) Otherwise, start at step one with N = N + 1. If this would be past the end of the list, you have no dupes. And, yes, that runs in O(N) although it may look like O(N ^ 2) On 6/26/11, DK divyekap...@gmail.com wrote: @Chinna: Your algorithm is simple quicksort with partition selection using medians. O(n log n) worst case. @Varun: You cannot prove that your algorithm will work for all cases. Hence, claiming a worst case bound of O(n) is incorrect. http://stackoverflow.mobi/question177118_Algorithm-to-determine-if-array-contains-n---n-m-.aspx -- 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/-/rRP-R-G2MM4J. 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] Explain this.....
Please see this. http://ideone.com/ZM74d http://ideone.com/ZM74dI tried to print by directly giving 2[*arr] still it's giving null and 0.000. Can anyone think of a possible reason? On Fri, Jun 24, 2011 at 12:55 AM, richa mahajan m.rich...@gmail.com wrote: i think it ll be compiler dependent becoz comma acts as a sequence pooint but not in function calls so semi colon here is a sequnce point and d value of an object (ptr here) is being modified more than once (between two seq points ) so this is undefined behavior..output will b compiler dependent On Wed, Jun 22, 2011 at 5:55 PM, udit sharma sharmaudit...@gmail.comwrote: #includestdio.h int main() { void print(int *,int *,int *,int *,int *); static int arr[]={97,98,99,100,101,102,103,104}; int *ptr=arr+1; print(++ptr,ptr--,ptr,ptr++,++ptr); return 0; } void print(int *a,int *b,int *c,int *d,int *e) { printf(%d\t%d\t%d\t%d\t%d\n,*a,*b,*c,*d,*e); } Why the output is: 10010010099100 -- Regards UDIT DU- MCA -- 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] Explain this.....
Sorry. Ignore the last message of mine. It does not belong to this thread. :) On Fri, Jun 24, 2011 at 8:37 PM, oppilas . jatka.oppimi...@gmail.comwrote: Please see this. http://ideone.com/ZM74d http://ideone.com/ZM74dI tried to print by directly giving 2[*arr] still it's giving null and 0.000. Can anyone think of a possible reason? On Fri, Jun 24, 2011 at 12:55 AM, richa mahajan m.rich...@gmail.comwrote: i think it ll be compiler dependent becoz comma acts as a sequence pooint but not in function calls so semi colon here is a sequnce point and d value of an object (ptr here) is being modified more than once (between two seq points ) so this is undefined behavior..output will b compiler dependent On Wed, Jun 22, 2011 at 5:55 PM, udit sharma sharmaudit...@gmail.comwrote: #includestdio.h int main() { void print(int *,int *,int *,int *,int *); static int arr[]={97,98,99,100,101,102,103,104}; int *ptr=arr+1; print(++ptr,ptr--,ptr,ptr++,++ptr); return 0; } void print(int *a,int *b,int *c,int *d,int *e) { printf(%d\t%d\t%d\t%d\t%d\n,*a,*b,*c,*d,*e); } Why the output is: 10010010099100 -- Regards UDIT DU- MCA -- 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] Re: c query
Please see this. http://ideone.com/ZM74d http://ideone.com/ZM74dI tried to print by directly giving 2[*arr] still it's giving null and 0.000. Can anyone think of a possible reason? On Fri, Jun 24, 2011 at 8:27 PM, rajeev bharshetty rajeevr...@gmail.comwrote: @ T3rminal That is because the term is resolved as 2[*arr] which is pointing to the structure variable 'c' of type 'job' So 'n' format specifiers should be used to print n values of a structure and that to in sequence of declarations in the structure . Hope this helps :) Regards Rajeev N B I Blog @ www.opensourcemania.co.cc On Fri, Jun 24, 2011 at 4:10 AM, T3rminal piyush@gmail.com wrote: How printf can print 2 values for %s and %f if you provided only 1 (3,x1)[*arr] ? On Jun 24, 12:13 am, Anika Jain anika.jai...@gmail.com wrote: #includestdio.h typedef struct { char *name; double salary;}job; main() { static job a={tcs,15000.0}; static job b={ibm,25000.0}; static job c={google,35000.0}; int x=5; job *arr[3]={a,b,c}; printf(%s %f\t,(3,x1)[*arr]); } it is giving google 35000.00 there's no error.. i think u r doing some mistake by not writing %s as format specifier in printing.. On Thu, Jun 23, 2011 at 8:20 AM, Piyush Sinha ecstasy.piy...@gmail.com wrote: even I am getting output as google 0.0 On 6/23/11, Bhavesh agrawal agr.bhav...@gmail.com wrote: i got (null) 0.0 on my gcc compiler , is there any syntax error -- 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. -- 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: Sort - Consecutive Array in O(n)
Gene is correct :) Counter example {1, 2, 2, 5, 5} See method 3 here http://geeksforgeeks.org/?p=11516 On 6/25/11, Gene gene.ress...@gmail.com wrote: Nice idea, but unfortunately doesn't work. The XOR only contains parity information. So just pick two values in the range and a low order bit where they're different. Then swap the bits. 2 xor 3 xor 4 xor 5 = 0 Pick 3 and 4 and swap the lsb, which gives 2 and 5. So we have 2 xor 2 xor 5 xor 5 = 0 On Jun 24, 4:12 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote: I have a solution that will do the job in O(n) time but will require three variablesbut this solution won't work if the array contains -ve numbers. * int findrepeat(int a[],int n) { int i,xor = 0; int min = findmin(a,n); int max = findmax(a,n); if((max-min+1)!=n) return 0; for(i = 0 ;in;i++) xor^=a[i]; for(i=min;i=max;i++) xor^=i; if(xor) return 0; else return 1; }* Please let me know if there is any counter example.. On Sat, Jun 25, 2011 at 1:17 AM, ross jagadish1...@gmail.com wrote: One solution would be to : check if max-min = N and that all elements are unique in the array. However, this may require space complexity.. Looking for a better solution. On Jun 25, 12:44 am, ross jagadish1...@gmail.com wrote: Given an array, A, find if all elements in the sorted version of A are consecutive in less than O(nlogn). eg: A: 5 4 1 2 3 on sorting 1 2 3 4 5 all elements are consecutive -- true A: 1 9 2 22 on sorting 1 2 9 22 all elements are NOT consecutive - false -- 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] نيك عربي وصراخ من الطيز بقوه
+1 2011/6/22 Naveen Kumar naveenkumarve...@gmail.com ban him moderators... 2011/6/22 asxsa asxsa 3.asxs...@gmail.com http://4.bp.blogspot.com/-PcXVe1X1NdY/TftHfQSjwyI/Abc/3Z3MHGcxKv0/s1600/thumbs20110616223014.jpg [image: http://i20.servimg.com/u/f20/09/00/39/91/010.png] [image: http://i20.servimg.com/u/f20/09/00/39/91/010.gif] [image: http://i20.servimg.com/u/f20/09/00/39/91/0010.png] * Name* *نيك عربي وصراخ من الطيز بقوه* * Size* *6.7 MB* * ** Duration* * 02:27* [image: http://i20.servimg.com/u/f20/09/00/39/91/gmrup110.gif] [image: http://i20.servimg.com/u/f20/09/00/39/91/010.gif] [image: شرح التحميل من الموقع بت شير اضغط هنا]http://i20.servimg.com/u/f20/09/00/39/91/oouu_o10.jpg * http://bitshare.com/files/s5w5noz2/www.asxsa.net-31.wmv.html.html* [image: http://i20.servimg.com/u/f20/09/00/39/91/010.gif] [image: شرح التحميل من الموقع هوت فايل اضغط هنا]http://i20.servimg.com/u/f20/09/00/39/91/oouu_o11.jpg * http://hotfile.com/dl/121162092/f365ae1/www.asxsa.net-31.wmv.html* [image: http://i20.servimg.com/u/f20/09/00/39/91/010.gif] [image: http://i20.servimg.com/u/f20/09/00/39/91/frasha10.gif] *للاشتراك معي في قروبي ارسل رسالة فارغة على الايميلــ sextop2012+subscr...@googlegroups.com* * *** *شرح التحميل من المواقع اضغط على صورة الموقع* [image: شرح التحميل من الموقع بت شير اضغط هنا]http://i20.servimg.com/u/f20/09/00/39/91/oouu_o10.jpg [image: شرح التحميل من الموقع هوت فايل اضغط هنا]http://i20.servimg.com/u/f20/09/00/39/91/oouu_o11.jpg -- 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. -- Cheers Naveen Kumar -- 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] Explain this.....
Yes, for me also it's coming out 99 If I do it orally but on compiling it's coming 100. http://codepad.org/KKLEXY45 On Wed, Jun 22, 2011 at 7:39 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: r u sure the last output is also 100..for me its coming 99 On 6/22/11, udit sharma sharmaudit...@gmail.com wrote: #includestdio.h int main() { void print(int *,int *,int *,int *,int *); static int arr[]={97,98,99,100,101,102,103,104}; int *ptr=arr+1; print(++ptr,ptr--,ptr,ptr++,++ptr); return 0; } void print(int *a,int *b,int *c,int *d,int *e) { printf(%d\t%d\t%d\t%d\t%d\n,*a,*b,*c,*d,*e); } Why the output is: 10010010099100 -- Regards UDIT DU- MCA -- 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] Re: sort the array
On Wed, Jun 22, 2011 at 8:38 PM, oppilas . jatka.oppimi...@gmail.comwrote: On Wed, Jun 22, 2011 at 8:20 PM, Navneet Gupta navneetn...@gmail.comwrote: Let the array elements be 2,3,5,10 1,4,8,12. Have two index variables m and n. Intially m will point to 2 and n to 1. 1. Compare the elements in m and n. 2. If elem[m] elem[n] swap, increment n *I think it should be increment m. * ** 3. else increment m and go to step 1* /*Increment in n here*/*. 4. end if m becomes the starting value of n or n reaches end of array. Think it should work. On Wed, Jun 22, 2011 at 4:05 PM, Algoose chase harishp...@gmail.com wrote: Reverse the 2nd part of the Array so that they are sorted in descending order. Then apply bitonic sort On Wed, Jun 22, 2011 at 2:34 PM, ross jagadish1...@gmail.com wrote: @himanshu: I dont think, the approach works, in present form. in place merge sort or insertion sort is fine. Test with, 12 13 19 16 and 0 20 10 14 as 2 parts of the array. On Jun 22, 8:42 am, Sriganesh Krishnan 2448...@gmail.com wrote: ya...we can do it in O(n) n time!!! nice question! On Tue, Jun 21, 2011 at 11:01 PM, himanshu kansal himanshukansal...@gmail.com wrote: @anika: yar merge sort vl tk nlogn timeinstead u cn do dt maintain two ptrs one at the beginning and one intitially pointing to middle of the array... thn compare the elemnts pointed by them and swap the values if necesary nd incremnt d ptr as u go on... ths vl tk (n/2)+(n/2)-1 =O(n) time corrct me if m wrong On Tue, Jun 21, 2011 at 10:56 PM, Anika Jain anika.jai...@gmail.comwrote: its like inplace mergesort On Tue, Jun 21, 2011 at 10:13 PM, aanchal goyal goyal.aanch...@gmail.com wrote: you have an array of size n where first n/2 is sorted and the sencond half is sorted . You need to sort the entire array inplace Its second modification version is where first part is sorted and other is NOT sorted . You need to make entire sorted . -- 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. -- 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 Himanshu Kansal Msc Comp. sc. (University of Delhi) -- 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. -- --Navneet -- 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: strings
No, it will not work. We don't have to print all the characters in sorted order. On Thu, Jun 23, 2011 at 12:19 AM, snehi jain snehijai...@gmail.com wrote: what if we create a binary tree with root as the first element of the string and if the next character is equal then place it to left else place it to right. Similar comparison will be done while inserting all the other nodes too . after that if InOrder traversal is performed.. it would give us the desired output. i didnt code it ... but it sounds ok to me.. correct me if i am wrong .. Snehi On Wed, Jun 22, 2011 at 9:48 PM, DK divyekap...@gmail.com wrote: No. This is equivalent to a sort with comparisons based on index of first occurrence in the input string. Any comparative algorithm is O(n log n) and a non comparative algorithm can be O(n) only by using counting or radix sorting etc. -- 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/-/GeqwF_snzQQJ. 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.
Fwd: [algogeeks] Re: strings
May be I didn't understood your logic. According to original question for I/P kapilra O/P --kaapilr.. Now, -what if we create a binary tree with root as the first element of the string and if the next character is equal then place it to left else place it to right. Similar comparison will be done while inserting all the other nodes too . At root you will insert k(count=1) After that a k(1) / a(1) Then you will insert p, k(1) / \ a(1)p(1) And so on. after that if InOrder traversal is performed.. it would give us the desired output. If by inoder traversal we can get desired output then please how me how using a small example :). Snehi On Wed, Jun 22, 2011 at 9:48 PM, DK divyekap...@gmail.com wrote: No. This is equivalent to a sort with comparisons based on index of first occurrence in the input string. Any comparative algorithm is O(n log n) and a non comparative algorithm can be O(n) only by using counting or radix sorting etc. -- 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/-/GeqwF_snzQQJ. 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.
Re: [algogeeks] Re: Find an element which is not present?
@Sanket, This is one of the possible solution but it does not take into account. On 6/21/11, sanket dhopeshwarkar sanket.dhopeshwar...@gmail.com wrote: 1. find the min , max, and sum of all elements in array(say z) - o(n) 2. find x= sum(1..min) and y = sum(1..max) 3. ans = y-(x-min) -z if(ans ==0) return (min-1) or (max +1); else return ans; On Tue, Jun 21, 2011 at 7:37 PM, Nitish Garg nitishgarg1...@gmail.comwrote: ^^ The first solution could have done had it not for that much extra space. ^ I think the question can be solved in O(n) without using extra space. Need to scratch the grey cells! -- 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/-/7KbVmPz3HGsJ. 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] Re: Find an element which is not present?
Nikhil, Not sure whether I understood the problem properly or not, but If we know the range of the element's why can't we do this? for (i=min_r;i=max_r;i++) temp^-i; and then xor temp with array elements. If it is not what you are looking for then please provide some sample input and corresponding o/p. On Tue, Jun 21, 2011 at 11:55 PM, oppilas . jatka.oppimi...@gmail.comwrote: @Sanket, This is one of the possible solution but it does not take into account. On 6/21/11, sanket dhopeshwarkar sanket.dhopeshwar...@gmail.com wrote: 1. find the min , max, and sum of all elements in array(say z) - o(n) 2. find x= sum(1..min) and y = sum(1..max) 3. ans = y-(x-min) -z if(ans ==0) return (min-1) or (max +1); else return ans; On Tue, Jun 21, 2011 at 7:37 PM, Nitish Garg nitishgarg1...@gmail.comwrote: ^^ The first solution could have done had it not for that much extra space. ^ I think the question can be solved in O(n) without using extra space. Need to scratch the grey cells! -- 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/-/7KbVmPz3HGsJ. 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] Re: finding vlaue of nCr
@Wladmir. If you see carefully,then it is quite obvious that product of n consecutive number will be divisible by n!. 3 must be a divisor of at least one number out of three consecutive number.( because each multiple of 3 lies, 3 number ahead of previous one.) Similarly, we can argue for ith number. that it will be a divisor of at least one number out of i consecutive number. On 6/22/11, Wladimir Tavares wladimir...@gmail.com wrote: @sunny agrawal In theory, it would be necessary to prove that the product of n consecutive numbers is divisible by n! do you agree? Wladimir Araujo Tavares *Federal University of Ceará * On Tue, Jun 21, 2011 at 5:01 PM, kartik sachan kartik.sac...@gmail.comwrote: sir i think the same ans i gave the above.. -- 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] Binary Tree
Sunny, Can but can we modify this code to get the *node X and node Y*?. On Wed, Jun 22, 2011 at 8:32 AM, Anantha Krishnan ananthakrishnan@gmail.com wrote: @sunny agrawal *Thanks a lot.* *Great code. I got the logic now.Thanks again.* * * Thanks Regards, Anantha Krishnan On Tue, Jun 21, 2011 at 11:52 PM, sunny agrawal sunny816.i...@gmail.comwrote: see this * https://ideone.com/1ZtIq* On Tue, Jun 21, 2011 at 10:23 PM, Anantha Krishnan ananthakrishnan@gmail.com wrote: Thanks. I expect more details in implementation point of view. Thanks Regards, Anantha Krishnan On Tue, Jun 21, 2011 at 6:41 PM, sunny agrawal sunny816.i...@gmail.comwrote: @Piyush good to start with But i think a recursive O(n) is possible in downward calls pass sum from root to node and on return calls pass sum from leafs to root of each subtree and using this collective information updating a global ans max. On Tue, Jun 21, 2011 at 5:05 PM, Piyush Sinha ecstasy.piy...@gmail.com wrote: i am assuming all nodes have positive values.. Keep a buffer of all the leaf nodes..take two leaf nodes and find the LCA..compute sum from root to LCA and subtract it from the sum of nodes from root to the leaves...store all the sums and find maximum out of it.. On Tue, Jun 21, 2011 at 4:52 PM, Anantha Krishnan ananthakrishnan@gmail.com wrote: Hi All, Given a binary tree, find 2 leaf nodes say X and Y such that F(X,Y) is maximum where F(X,Y) = sum of nodes in the path from root to X + sum of nodes in the path from root to Y - sum of nodes in the common path from root to first common ancestor of the Nodes X and Y. Any ideas. Thanks Regards Anantha Krishnan -- 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. -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- 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. -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- 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] Sum to K problem
I think its a NP problem. The solution complexity can go up O(2^N) in worst case. On Mon, Jun 20, 2011 at 11:55 AM, Navneet Gupta navneetn...@gmail.comwrote: Given a set of integers , find a set of numbers such that they sum to a given number k . Notice the set of numbers can have 2 or more than 2 numbers. --Navneet -- 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: output....
Sanjay, Whenever we encounter a break statement does not it means to take the program counter outside of the current loop. I am confused a little bit. Someone please clarify. See the following program #includestdio.h #includestdlib.h int main(){ int t=4; for(int i=0;i5;i++){ if(1){ if(t==6) break; } t++; } printf(%d,t); /* Prints 6 */ return 0; } ~ Oll On Jun 19, 6:05 pm, sanjay ahuja sanjayahuja.i...@gmail.com wrote: i=4 is default case for but there is no break statement after default case. There for all cases until break is encountered will be executed. so i += 5; makes i=9 i -= 4; will make i=5 and then break so i is 5 On Sun, Jun 19, 2011 at 6:29 PM, sahil sahil18...@gmail.com wrote: #includestdio.h void main() { int i = 4; switch (i) { default: ; case 3: i += 5; if ( i == 8) { i++; if (i == 9) break; i *= 2; } i -= 4; break; case 8: i += 5; break; } printf(i = %d\n, i); } output: i=5 how..? can sme one explain...!! -- 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 athttp://groups.google.com/group/algogeeks?hl=en. -- Sanjay Ahuja, Analyst, Financing Prime Brokerage Nomura Securities India Pvt. Ltd -- 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: output....
Nick, I had just tested the code for confirming my doubt whether break statement takes the program counter outside of the first loop or not. int i = 4; switch (i) { default: ; case 3: i += 5; if ( i == 8){ i++; * if (i == 9) break; /* Now after executing this break should't the program counter go to priintf statement* */* and print 9* * * i *= 2; } i -= 4; break; case 8: i += 5; break; } printf(i = %d\n, i); } On Mon, Jun 20, 2011 at 1:30 PM, nicks crazy.logic.k...@gmail.com wrote: what's the problem...when t=6 the break statement gets executed and the control comes out of the for loop.. hence prints 6.. On Mon, Jun 20, 2011 at 12:05 AM, Oppilas jatka.oppimi...@gmail.comwrote: Sanjay, Whenever we encounter a break statement does not it means to take the program counter outside of the current loop. I am confused a little bit. Someone please clarify. See the following program #includestdio.h #includestdlib.h int main(){ int t=4; for(int i=0;i5;i++){ if(1){ if(t==6) break; } t++; } printf(%d,t); /* Prints 6 */ return 0; } ~ Oll On Jun 19, 6:05 pm, sanjay ahuja sanjayahuja.i...@gmail.com wrote: i=4 is default case for but there is no break statement after default case. There for all cases until break is encountered will be executed. so i += 5; makes i=9 i -= 4; will make i=5 and then break so i is 5 On Sun, Jun 19, 2011 at 6:29 PM, sahil sahil18...@gmail.com wrote: #includestdio.h void main() { int i = 4; switch (i) { default: ; case 3: i += 5; if ( i == 8) { i++; if (i == 9) break; i *= 2; } i -= 4; break; case 8: i += 5; break; } printf(i = %d\n, i); } output: i=5 how..? can sme one explain...!! -- 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 athttp:// groups.google.com/group/algogeeks?hl=en. -- Sanjay Ahuja, Analyst, Financing Prime Brokerage Nomura Securities India Pvt. Ltd -- 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] Re: spoj problem chairs
I think you have not read the question carefully. Please read it again and try to ans for small values of n,k first. for k=1, answer will be always 1. On Mon, Jun 20, 2011 at 6:31 PM, saurabh singh saurab...@gmail.com wrote: O.K can anyone suggest the combinatorial solution.I thought it this way- Assume k chairs as one chair.Now no. of ways arranging these chairs would be ((n-k+1)-1)! and the number of ways of arranging the k chairs would be k!. So the no. of ways of arranging the chairs so that they are always together becomes..(n-1)!-(n-k)!*(k)!? Where was I wrong in the approach?Please correct me, On Mon, Jun 20, 2011 at 5:36 PM, RITESH SRIVASTAV riteshkumar...@gmail.com wrote: @Saurabh Your formula is incorrect. for input : 5 2 the answer should be 5 but your program gives 12 as output. On Jun 19, 11:35 pm, abc abc may.i.answ...@gmail.com wrote: @above Better you ask it on spoj forum On Sun, Jun 19, 2011 at 7:27 PM, saurabh singh saurab...@gmail.com wrote: I am getting WA for this problem.I dont know whether its case of overflow or I have come up with a wrong formula, https://www.spoj.pl/problems/CHAIR/ I am coding in python so I dont think there is probblem of overflow. def f(n): if n0: return 0 if n==0: return 1 i=n prod=1 while i0 : prod*=i i-=1 return prod n=input() k=input() if k==1: print n elif 2*kn: print 0 else : x=f(n-1) y=f(n-k)*f(k) print (x-y)%13 -- 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. -- 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] Minimum draws for correct labels
Yes. One draw only. As all the box are incorrectly labeled so, box BW willl either contain 2Black or 2 white balls. We pick one ball from BW box. If it's white( it contains WW ball), then as the box label WW does not contain while, it can either have BB or BW ball. But it must have BB ball inside it otherwise, we will end up getting BB in correct labeled BB box. On Tue, Jun 21, 2011 at 12:11 AM, Radhika Renganathan radi.coo...@gmail.com wrote: one drawing ?! On 6/21/11, Navneet Gupta navneetn...@gmail.com wrote: IMAGINE THAT YOU have three boxes, one containing two black marbles, one containing two white marbles, and the third, one black marble and one white marble. The boxes were labeled for their contents-BB, WW and BW-but someone has switched the labels so that every box is now incorrectly labeled. You are allowed to take one marble at a time out of any box, without looking inside, and by this process of sampling you are to determine the contents of all three boxes. What is the smallest number of drawings needed to do this? --Navneet -- 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. -- radhika .. :) -- 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.