Re: [algogeeks] Re: AMAZON: given col id, print col name in excel
@yq, didn't I ask you this question before? On Fri, Aug 10, 2012 at 4:48 PM, yq Zhang zhangyunq...@gmail.com wrote: @shiv, your code is correct go compute the base 26 number. However, this question is not base 26 number obviously. On Wed, Aug 8, 2012 at 4:46 AM, shiv narayan narayan.shiv...@gmail.com wrote: this is similar to conversion of no in base 26.( where digits are a,b,c,d...z) just think it like decimal to binary conversion here base is instead 26. char Carr[26]={a,b,c...z} i=0; int arr[]; do { arrr[i++]=n%26; n/=2; } while(n) ; for(int i=n-1;i=0;i--) coutCarr[a[i]]; correct me if i am wrong. On Wednesday, 8 August 2012 12:56:56 UTC+5:30, ashgoel wrote: Imagine a sequence like this: a, b, c...z, aa, ab, ac...zz, aaa, aab, aac aax, aaz, aba, abc... (Its same as excel column names). Given an integer (n), generate n-th string from the above sequence. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- 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/-/Z3kYiTZi_F8J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] one more from amazon
public static ArrayListArrayListInteger Partition(int val, int start, int size) { ArrayListArrayListInteger r = new ArrayListArrayListInteger(); if (start * size val) { return null; } if(size == 1) { r.add(new ArrayListInteger()); r.get(0).add(val); return r; } for (int i = start; i = val/size; i++) { ArrayListArrayListInteger tr = Partition(val - i, i, size - 1); if (tr != null) { for (int j = 0; j tr.size(); j++) { ArrayListInteger subr = tr.get(j); subr.add(i); } r.addAll(tr); } } return r; } On Sun, Feb 6, 2011 at 7:51 AM, Gajendra Dadheech gajju3...@gmail.comwrote: Write a function to print all unique partitions on n tht are of size m. eg: n=10, m=4. it should print 7 1 1 1, 6 2 1 1, 5 3 1 1, 3 3 2 2,, so on Thanks and regards, Gajendra Dadheech hi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Excel Sheet Question Asked
@albert, You need to becareful when doing the divide, because there is no ZERO. (Z - AA not Z-A0). here is the code: public static String ExcelMapIntToStr(int n) { StringBuilder sb = new StringBuilder(); while(n0) { sb.append((char)(('A' - 1) + (n-1)%26 + 1)); n = (n-1)/26; } return sb.reverse().toString(); } public static int ExcelMapStrToInt(String str) { int val = 0; int base = 1; for(int i = str.length() - 1; i=0; i--) { val += (str.charAt(i) - ('A' - 1))*base; base *= 26; } return val; } On Tue, Feb 1, 2011 at 10:39 AM, albert theboss alberttheb...@gmail.comwrote: Simply L division by 26 gives the answer ... like decimal to binary conversion thats 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.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Again
For any gas pump, when your car arrives, it contains 0 or more gas. So, for each gas pump, the worst case is starting from that pump. Then, if we starting from pump A1, passed A2 - Ak and failed at Ak+1. for A1 to Ak, we can not pass Ak+1 starting from any of them. So we try start from Ak+1. This could be solved in liner time. finding a possible start pump use O(n) and prove it use another O(n). -weiq On Sat, Jan 29, 2011 at 9:47 PM, nishaanth nishaant...@gmail.com wrote: @Wei.Qi Can you clarify when your algorithm terminates and also what is the running time of the algorithm ? On Sun, Jan 30, 2011 at 9:46 AM, yq Zhang zhangyunq...@gmail.com wrote: can you prove it? On Jan 29, 2011 6:38 PM, Wei.QI qiw...@gmail.com wrote: Starting with any pump A, try to finish the circle, if at pump B that can not reach pump B+1, it means all pumps from A to B can not finish the circle (it will go broke at pump B), then just start with B+1. After go through all the pumps start from some pump, we got an answer. if we go back to pump A and later, still can not find an answer, there is no answer. On Sat, Jan 29, 2011 at 4:38 AM, sankalp srivastava richi.sankalp1...@gmail.com wrote: I'm sure you have misstated the problem statement just find out the total path length and return the first petrol pump which gives you the required milage go greedy On Jan 28, 5:09 pm, bittu shashank7andr...@gmail.com wrote: There are N petrol pumps along a circular path. Every petrol pump gives some amount of fixed petrol. Need not to be unique and in no particular order means it is random. We have a car and we need to find a petrol pump which can provide so much of petrol that we can take a full of the circle. Mileage of car is fixed. Distance between adjacent petrol pumps are given. Thanks Regards Shashank -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- S.Nishaanth, Computer Science and engineering, IIT Madras. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Again
Starting with any pump A, try to finish the circle, if at pump B that can not reach pump B+1, it means all pumps from A to B can not finish the circle (it will go broke at pump B), then just start with B+1. After go through all the pumps start from some pump, we got an answer. if we go back to pump A and later, still can not find an answer, there is no answer. On Sat, Jan 29, 2011 at 4:38 AM, sankalp srivastava richi.sankalp1...@gmail.com wrote: I'm sure you have misstated the problem statement just find out the total path length and return the first petrol pump which gives you the required milage go greedy On Jan 28, 5:09 pm, bittu shashank7andr...@gmail.com wrote: There are N petrol pumps along a circular path. Every petrol pump gives some amount of fixed petrol. Need not to be unique and in no particular order means it is random. We have a car and we need to find a petrol pump which can provide so much of petrol that we can take a full of the circle. Mileage of car is fixed. Distance between adjacent petrol pumps are given. Thanks Regards Shashank -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: google written
@Jammy There is a bug at line if(startnext == current || a[startnext] a[currentnext]) { if(current currentnext) { break; }else { current = currentnext; // +1; should not move forward here, } } On Sat, Jan 15, 2011 at 1:55 PM, Jammy xujiayiy...@gmail.com wrote: @Wei Please test you code on cdbbcbbca. I believe it outputs 2 instead of 8. On Jan 14, 4:09 am, Wei.QI qiw...@gmail.com wrote: FindStartIndex(char[] a) { int start = 0; int current = 1; while(current a.Length) { if(a[current] a[start]) { start = current; ++current; }else if(a[current] a[start]) { ++current; }else //a[current] == a[start] { int lookforward = 0; int startnext = start; int currentnext = current; while(startnext != currnet a[startnext] == a[currentnext]) { ++lookforward; startnext = (start + lookforward) % a.Length; currentnext = (current + lookforward) % a.Length; }//finish when compare to current head or there is different if(startnext == current || a[startnext] a[currentnext]) { if(current currentnext) { break; }else { current = currentnext+1; } } else //a[startnext] a[currentnext] { start = current; if(current currentnext) { current = currentnext + 1; }else { break; } } } } return start; } On Fri, Jan 14, 2011 at 12:45 AM, radha krishnan radhakrishnance...@gmail.com wrote: There s O(n) solution for this :) On Fri, Jan 14, 2011 at 2:13 PM, radha krishnan radhakrishnance...@gmail.com wrote: append the string to original string and index=answer of that spoj problem now u can ouput the string from index to index+strlen(originalstring)-1 On Fri, Jan 14, 2011 at 2:12 PM, radha krishnan radhakrishnance...@gmail.com wrote: wow This s a spoj problem http://www.spoj.pl/problems/MINMOVE/ On Fri, Jan 14, 2011 at 1:40 PM, snehal jain learner@gmail.com wrote: Write the code to find lexicographic minimum in a circular array, e.g. for the array BCABDADAB, the lexicographic mininum is ABBCABDAD. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com algogeeks%2Bunsubscribe@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.comalgogeeks%2bunsubscr...@googlegroups.com algogeeks%2Bunsubscribe@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.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] probability
x is even number probability 0.9x + x = 1 x = 1/1.9 P(2) = P(4) = P(6) = (1 / 1.9) / 3 P(4|5|6) = (P(4) + P(6)) / 0.75 = 2 / 1.9 / 3 / 0.75 = 0.4678362573099415 -weiq On Thu, Jan 13, 2011 at 11:29 PM, snehal jain learner@gmail.com wrote: An unbalanced dice (with 6 faces, numbered from 1 to 6) is thrown. The probability that the face value is odd is 90% of the probability that the face value is even. The probability of getting any even numbered face is the same. If the probability that the face is even given that it is greater than 3 is 0.75, which one of the following options is closest to the probability that the face value exceeds 3? (A) 0.453 (B) 0.468 (C) 0.485 (D) 0.492 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] google written
FindStartIndex(char[] a) { int start = 0; int current = 1; while(current a.Length) { if(a[current] a[start]) { start = current; ++current; }else if(a[current] a[start]) { ++current; }else //a[current] == a[start] { int lookforward = 0; int startnext = start; int currentnext = current; while(startnext != currnet a[startnext] == a[currentnext]) { ++lookforward; startnext = (start + lookforward) % a.Length; currentnext = (current + lookforward) % a.Length; }//finish when compare to current head or there is different if(startnext == current || a[startnext] a[currentnext]) { if(current currentnext) { break; }else { current = currentnext+1; } } else //a[startnext] a[currentnext] { start = current; if(current currentnext) { current = currentnext + 1; }else { break; } } } } return start; } On Fri, Jan 14, 2011 at 12:45 AM, radha krishnan radhakrishnance...@gmail.com wrote: There s O(n) solution for this :) On Fri, Jan 14, 2011 at 2:13 PM, radha krishnan radhakrishnance...@gmail.com wrote: append the string to original string and index=answer of that spoj problem now u can ouput the string from index to index+strlen(originalstring)-1 On Fri, Jan 14, 2011 at 2:12 PM, radha krishnan radhakrishnance...@gmail.com wrote: wow This s a spoj problem http://www.spoj.pl/problems/MINMOVE/ On Fri, Jan 14, 2011 at 1:40 PM, snehal jain learner@gmail.com wrote: Write the code to find lexicographic minimum in a circular array, e.g. for the array BCABDADAB, the lexicographic mininum is ABBCABDAD. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] google written
@juver++, can you give me a test case that will time out? On Fri, Jan 14, 2011 at 6:44 AM, juver++ avpostni...@gmail.com wrote: @qw I think you solution will timed 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.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.