[algogeeks] print spiral
given a matrix m*n print elements in spiral eg 1 2 3 4 5 6 = 1,2,4,6,5,3 1 2 3 =1,2,3 i wrote following code but for the case 2 printing 1,2,3,2 I wish to avoid keeping a counter of how many elements have been print so far... void spiral(int a[], int m, int n) { while ( (rs(m+1)/2) (cs (n+1)/2)) { int r=rs; int c=cs; for (int j=c;jn-c-1;j++) printf(%d ,a[r][j]); for (int i=r;im-r-1;i++) printf(%d ,a[i][n-c-1]); for (int j=n-c-1;jc;j--) printf(%d ,a[m-r-1][j]); for (int i=m-r-1;ir;i--) printf(%d ,a[i][c]);; rs++;cs++; } } 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 post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] water trap
question @ http://www.leetcode.com/groups/twitter-interview/forum/topic/rain-water-trap-2d-version/ can someone help please 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 post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] print spiral
void spiral(int a[][],int m,int n) { int c=1; -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Microsoft Interview Question
void change(int a[],int n) { int i,j; i=0; j=1; while(injn) { if(ji) j=i+1; else if(a[j]0a[i]0) { swap(a,j,i); } else { if(a[j]0) j++; else i++; } } } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Question
@guneesh your code fails to keep order b/w 3 and 4 in the above example On Fri, Jun 15, 2012 at 2:40 PM, Guneesh Paul Singh gunees...@gmail.comwrote: void change(int a[],int n) { int i,j; i=0; j=1; while(injn) { if(ji) j=i+1; else if(a[j]0a[i]0) { swap(a,j,i); } else { if(a[j]0) j++; else i++; } } } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] print spiral
check no. of elements printed in all inner for loop also for (int j=c;jn-c-1 cntm*n;j++) {printf(%d ,a[r][j]); cnt++;} for (int i=r;im-r-1 cntm*n;i++) {printf(%d ,a[i][n-c-1]); cnt++} for (int j=n-c-1 cntm*n;jc;j--) {printf(%d ,a[m-r-1][j]); cnt++} for (int i=m-r-1 cntm*n;ir;i--) {printf(%d ,a[i][c]); cnt++} On Fri, Jun 15, 2012 at 2:10 PM, Guneesh Paul Singh gunees...@gmail.comwrote: void spiral(int a[][],int m,int n) { int c=1; -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Utsav Sharma, 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.
Re: [algogeeks] water trap
pls explain the output On Fri, Jun 15, 2012 at 1:13 PM, Ashish Goel ashg...@gmail.com wrote: question @ http://www.leetcode.com/groups/twitter-interview/forum/topic/rain-water-trap-2d-version/ can someone help please 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 post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Utsav Sharma, 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.
Re: [algogeeks] 4Sum
Its simple varition of 3 sum problem , using hask table u can easily do it . let s=a+b+c+d can be written as b+c+d=s-a; - 3 SUM Try it let me know i find any difficulty :) On Fri, Jun 15, 2012 at 3:50 PM, Akshat Sapra sapraaks...@gmail.com wrote: Given an array *S* of *n* integers, are there elements *a*, *b*, *c*, and *d* in *S* such that *a* + *b* + *c* + *d* = target? Find all unique quadruplets in the array which gives the sum of target. -- Akshat Sapra Under Graduation(B.Tech) IIIT-Allahabad(Amethi Campus) *--* sapraaks...@gmail.com akshatsapr...@gmail.com rit20009008@ rit20009...@gmail.comiiita.ac.in -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Thanks Shashank Mani Narayan Computer Science Engineering Birla Institute of Technology,Mesra ** Founder Cracking The Code Lab http://shashank7s.blogspot.com/; FB Page http://www.facebook.com/pages/Cracking-The-Code/148241881919895 Google+ http://gplus.to/wgpshashank Twitter https://twitter.com/wgpshashankhttps://twitter.com/#%21/wgpshashank Puzzled Guy @ http://ashutosh7s.blogspot.com** **FB Page http://www.facebook.com/Puzzles.For.Puzzled.Minds* * Key Person Algogeek https://groups.google.com/forum/#!forum /algogeekshttps://groups.google.com/forum/#%21forum/algogeeks **Cell +91-9740852296 * * ** * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Basics of Cloud Computing
could you please provide free E-copy ? On Saturday, 9 June 2012 22:00:52 UTC+5:30, Ravi wrote: Hi All, Hope you are all doing great. I am a cloud engineer and specialize in cloud computing development and architecting as well big data analysis. Check out my blog for my views @ http://www.cloudcer.com I have recently published my first book. Its' based on cloud computing basics for the beginners. It covers the various aspects of cloud computing and virtualization and services provided by all the major cloud providers in all the service models like IaaS, PaaS SaaS. You can find the the book here: http://www.amazon.com/dp/B0083TC47C Be Well, Ravi Shankar -- 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/-/ULRFovABFEAJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Can anyone plz explain how we get this output
although we know this is compiler dependent , but still such questions are very frequent in some local competitions and can be found in some old books too. is it possible to have such questions in any company placement paper or interview ? On Thursday, 14 June 2012 11:41:04 UTC+5:30, Ajesh js wrote: main() { int a=10,b=5; printf(%d %d %d\n,a++,a,++a); printf(%d %d %d\n,++b,b,b++); } output 11 12 12 7 7 5 -- 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/-/L_rlqCezgtQJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Amazon Interview Question
You can use a trie with end of word marked by its corresponding entry in array. On Thursday, 14 June 2012 13:01:00 UTC+5:30, Mohit Rathi wrote: Hi, *There are two arrays of length 100 each. Each of these has initially n (n=100) elements. First array contains names and the second array contains numbers such that ith name in array1 corresponds to ith number in array2. Write a program which asks the user to enter a name, finds it in array1,* *a. if it exists, then print the corresponding number in array2, b. else ask the user to input its associated number and add the number and name to array2 and array1 respectively, and update the size of list* I can think of solving it through linear walk to the array. Anyone with more optimized algorithm like BST or HashTable? comments are welcome Thanks -- 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/-/9qAftPBlTEEJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Interview Question
+1 for trie.. -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad http://gplus.to/amolsharma99 http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://www.simplyamol.blogspot.com/ On Fri, Jun 15, 2012 at 5:21 PM, enchantress elaenjoy...@gmail.com wrote: se a trie with end of word marked by its corresponding entry in array. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] 4Sum
Complexity : O(n^3) import java.util.*; public class Solution { public ArrayListArrayListInteger fourSum(int[] num, int target) { // Start typing your Java solution below // DO NOT write main() function ArrayListArrayListInteger arr=new ArrayListArrayListInteger(); Arrays.sort(num); int n=num.length; int sum=0; for(int i=0;in-3;i++) { int a=num[i]; for(int j=i+1;jn-2;j++) { int b=num[j]; int k=j+1; int l=n-1; while(kl) { int c=num[k]; int d=num[l]; if(a+b+c+d target) k++; else if(a+b+c+d target) l--; else { ArrayListInteger al=new ArrayListInteger(); al.add(a); al.add(b); al.add(c); al.add(d); if(!arr.contains(al)) arr.add(al); k++; } } } } return arr; } } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: No of tri-angles
this is the running code to find no of triangles using brute force technique logic: in a triangle having sides a,b,c; then a+bc(if c is greatest side) correct me if i am wrong. #includeiostream #includeconio.h using namespace std; int max(int a,int b,int c) { return ((ab?a:b)c?(ab?a:b):c); } int main() { int n,a[120],t,p,q; cint; while(t--) { cinn; for(int i=0;in;i++) cina[i]; int i,j,no_of_triangles=0,sum=0,largest_edge; for(i=0;in-2;i++) { for(j=i+2;jn;j++) { sum=a[i]+a[i+1]+a[j]; largest_edge=max(a[i],a[i+1],a[j]); if(sum-largest_edgelargest_edge) { no_of_triangles++; couta[i] a[i+1] a[j]\n;} } } coutno_of_trianglesendl; } getch(); return 0; } On Wednesday, 13 June 2012 22:18:01 UTC+5:30, payel roy wrote: Let's say there are N sides are given. Length of them are like 1,2,3,4,5,N. How do you determine how many tri-angles can be made out of these N sides? -- 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/-/WizMjfsoizsJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] print spiral
yes, using count i solved this, but IMHO, this should be done without this count somehow.. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jun 15, 2012 at 3:14 PM, utsav sharma utsav.sharm...@gmail.comwrote: check no. of elements printed in all inner for loop also for (int j=c;jn-c-1 cntm*n;j++) {printf(%d ,a[r][j]); cnt++;} for (int i=r;im-r-1 cntm*n;i++) {printf(%d ,a[i][n-c-1]); cnt++} for (int j=n-c-1 cntm*n;jc;j--) {printf(%d ,a[m-r-1][j]); cnt++} for (int i=m-r-1 cntm*n;ir;i--) {printf(%d ,a[i][c]); cnt++} On Fri, Jun 15, 2012 at 2:10 PM, Guneesh Paul Singh gunees...@gmail.comwrote: void spiral(int a[][],int m,int n) { int c=1; -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Utsav Sharma, 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] Re: No of tri-angles
sry ignore the last comment for i wanted to say - your algo will work only when the numbers given are consecutive. -- Amol Sharma Final Year Student Computer Science and Engineering MNNIT Allahabad http://gplus.to/amolsharma99 http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://www.simplyamol.blogspot.com/http://facebook.com/amolsharma99 On Fri, Jun 15, 2012 at 8:06 PM, Amol Sharma amolsharm...@gmail.com wrote: @enchantress : your algo will work only when the number given are positive. -- Amol Sharma Final Year Student Computer Science and Engineering MNNIT Allahabad http://gplus.to/amolsharma99 http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://www.simplyamol.blogspot.com/ On Fri, Jun 15, 2012 at 7:01 PM, shiv narayan narayan.shiv...@gmail.comwrote: this is the running code to find no of triangles using brute force technique logic: in a triangle having sides a,b,c; then a+bc(if c is greatest side) correct me if i am wrong. #includeiostream #includeconio.h using namespace std; int max(int a,int b,int c) { return ((ab?a:b)c?(ab?a:b):c); } int main() { int n,a[120],t,p,q; cint; while(t--) { cinn; for(int i=0;in;i++) cina[i]; int i,j,no_of_triangles=0,sum=0,largest_edge; for(i=0;in-2;i++) { for(j=i+2;jn;j++) { sum=a[i]+a[i+1]+a[j]; largest_edge=max(a[i],a[i+1],a[j]); if(sum-largest_edgelargest_edge) { no_of_triangles++; couta[i] a[i+1] a[j]\n;} } } coutno_of_trianglesendl; } getch(); return 0; } On Wednesday, 13 June 2012 22:18:01 UTC+5:30, payel roy wrote: Let's say there are N sides are given. Length of them are like 1,2,3,4,5,N. How do you determine how many tri-angles can be made out of these N sides? -- 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/-/WizMjfsoizsJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] 4Sum
O(n^3) is straight forward: find all triplets and store them in an array say sum. and then for each triplet do binary search for (target-sum[i]) in the given array. is solution better than O(n^3) possible ? -- Amol Sharma Final Year Student Computer Science and Engineering MNNIT Allahabad http://gplus.to/amolsharma99 http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://www.simplyamol.blogspot.com/http://facebook.com/amolsharma99 On Fri, Jun 15, 2012 at 6:53 PM, Karthikeyan V.B kartmu...@gmail.comwrote: Complexity : O(n^3) import java.util.*; public class Solution { public ArrayListArrayListInteger fourSum(int[] num, int target) { // Start typing your Java solution below // DO NOT write main() function ArrayListArrayListInteger arr=new ArrayListArrayListInteger(); Arrays.sort(num); int n=num.length; int sum=0; for(int i=0;in-3;i++) { int a=num[i]; for(int j=i+1;jn-2;j++) { int b=num[j]; int k=j+1; int l=n-1; while(kl) { int c=num[k]; int d=num[l]; if(a+b+c+d target) k++; else if(a+b+c+d target) l--; else { ArrayListInteger al=new ArrayListInteger(); al.add(a); al.add(b); al.add(c); al.add(d); if(!arr.contains(al)) arr.add(al); k++; } } } } return arr; } } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] water trap
Hi, I solved it with a recursive solution and published in my blog : http://codingways.blogspot.com/2012/06/rain-water-trap-problem-2d-version.html please let me know if you have any idea. Regards, Hassan On Fri, Jun 15, 2012 at 2:15 PM, utsav sharma utsav.sharm...@gmail.comwrote: pls explain the output On Fri, Jun 15, 2012 at 1:13 PM, Ashish Goel ashg...@gmail.com wrote: question @ http://www.leetcode.com/groups/twitter-interview/forum/topic/rain-water-trap-2d-version/ can someone help please 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 post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Utsav Sharma, 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] 4Sum
Find all b[k]=a[i]+a[j] for the given array a. Iterate over all elements of this array b. Let the sum be (a+b). Now binary search (target - (a+b) ) in the array b. Complexity : O( (N^2)( log (N^2) ) ) Correct me if i am wrong. On Fri, Jun 15, 2012 at 8:41 PM, Amol Sharma amolsharm...@gmail.com wrote: O(n^3) is straight forward: find all triplets and store them in an array say sum. and then for each triplet do binary search for (target-sum[i]) in the given array. is solution better than O(n^3) possible ? -- Amol Sharma Final Year Student Computer Science and Engineering MNNIT Allahabad http://gplus.to/amolsharma99 http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://www.simplyamol.blogspot.com/http://facebook.com/amolsharma99 On Fri, Jun 15, 2012 at 6:53 PM, Karthikeyan V.B kartmu...@gmail.comwrote: Complexity : O(n^3) import java.util.*; public class Solution { public ArrayListArrayListInteger fourSum(int[] num, int target) { // Start typing your Java solution below // DO NOT write main() function ArrayListArrayListInteger arr=new ArrayListArrayListInteger(); Arrays.sort(num); int n=num.length; int sum=0; for(int i=0;in-3;i++) { int a=num[i]; for(int j=i+1;jn-2;j++) { int b=num[j]; int k=j+1; int l=n-1; while(kl) { int c=num[k]; int d=num[l]; if(a+b+c+d target) k++; else if(a+b+c+d target) l--; else { ArrayListInteger al=new ArrayListInteger(); al.add(a); al.add(b); al.add(c); al.add(d); if(!arr.contains(al)) arr.add(al); k++; } } } } return arr; } } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Hemesh singh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Book Feedback needed for book from Narasimha Karumanchi
@Saurabh : That's http://www.squifer.com/ http://www.squifer.com/document/e6e6192d75/Data-Structures-And-Algorithms-Made-Easy-%28for-Interviews%29-Programming-Interview-Questions/ Some chapters of the book are available here. On Thu, Jun 14, 2012 at 11:46 PM, saurabh singh saurab...@gmail.com wrote: Kindly find some other group for requesting e-books- www.squiffer.com This is a good reference for ebooks.Any more requests for uploading ebooks may result in a ban from the group. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri, Jun 8, 2012 at 7:05 PM, Decipher ankurseth...@gmail.com wrote: Does anybody has its ebook ? Please upload it -- 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/-/AETPnqJps7AJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Hemesh singh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Directi Question
At first look it appears to be a simple problem of discrete binary search. Take sum of b[i] as the upper_bound and 0 as the lower bound. Then apply a simple binary search for the number of pages that can be given to a student. Complexity : O(N log( sum( B ) ) ) On Thu, Jun 14, 2012 at 12:26 PM, algogeek dayanidhi.haris...@gmail.comwrote: In a library there are N books with the number of pages in i th book given by bi . These books are to be distributed among K students such that the difference between the largest sum of pages in the books assigned to any student and the smallest sum of number of pages in the books assigned to any student is minimum for the given input. Also the books are arranged in a certain order and this order must never be changed. For eg: suppose B[ ] contains the number of pages in each book. then N=6 K=3 B={3,7,8,2,6,4} then the output will be 0 as we can give book 1 and 2 to student 1 and book 3 and 4 to student 2 and the remaining to student 3. That makes 10 pages for student 1 10 for 2 and 10 for 3 and thus the difference is 0 similarly if B={3,6,8,2,6,4} then the minimum difference will be 1 . -- 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/-/JjKITS_gN9UJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Hemesh singh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] 4Sum
@hemesh cud u plz elaborate wat is b[k]=a[i]+a[j]...n also ur solution... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Directi Question
wat constraints does dis bring in the question... Also the books are arranged in a certain order and this order must never be changed. does this imply --- a student gets only consecutivly numbered book if not then sort the array B in decreasing order in Onlogn take another array S of k elements traverse B(sorted) S[i]=B[i] when first k elemnts traversed then traverse again k elemnts of B and S[2*k-i]+=B[i])...again S[i-2*k]+=B[i][.so on till B is traversed completely.. On Sat, Jun 16, 2012 at 2:22 AM, Hemesh Singh hemesh.mn...@gmail.comwrote: At first look it appears to be a simple problem of discrete binary search. Take sum of b[i] as the upper_bound and 0 as the lower bound. Then apply a simple binary search for the number of pages that can be given to a student. Complexity : O(N log( sum( B ) ) ) On Thu, Jun 14, 2012 at 12:26 PM, algogeek dayanidhi.haris...@gmail.comwrote: In a library there are N books with the number of pages in i th book given by bi . These books are to be distributed among K students such that the difference between the largest sum of pages in the books assigned to any student and the smallest sum of number of pages in the books assigned to any student is minimum for the given input. Also the books are arranged in a certain order and this order must never be changed. For eg: suppose B[ ] contains the number of pages in each book. then N=6 K=3 B={3,7,8,2,6,4} then the output will be 0 as we can give book 1 and 2 to student 1 and book 3 and 4 to student 2 and the remaining to student 3. That makes 10 pages for student 1 10 for 2 and 10 for 3 and thus the difference is 0 similarly if B={3,6,8,2,6,4} then the minimum difference will be 1 . -- 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/-/JjKITS_gN9UJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Hemesh singh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Directi question-centre of the tree
+ 1 for DK's solution. Is that a standard algorithm coz I feel like I have heard it somewhere ?? On Mon, Aug 8, 2011 at 1:37 AM, DK divyekap...@gmail.com wrote: @KK: DFS and BFS are O(N) and Floyd Warshall is O(N^3). Could you please state how you can use the traversals directly to get the center? (And prove your correctness too?) The solution given by Wladimir ( expanded upon by me) is O(N) and uses (somewhat) the inverse of a BFS as a traversal. -- DK http://twitter.com/divyekapoor http://gplus.to/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/-/HnMOZtOrkqwJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Hemesh singh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Book Feedback needed for book from Narasimha Karumanchi
bought this book and i am quite impressed with the quantity and quality of code. Recommend this with programming pearls, prog interview exposed, cracking the coding interview. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Sat, Jun 16, 2012 at 2:01 AM, Hemesh Singh hemesh.mn...@gmail.comwrote: @Saurabh : That's http://www.squifer.com/ http://www.squifer.com/document/e6e6192d75/Data-Structures-And-Algorithms-Made-Easy-%28for-Interviews%29-Programming-Interview-Questions/ Some chapters of the book are available here. On Thu, Jun 14, 2012 at 11:46 PM, saurabh singh saurab...@gmail.comwrote: Kindly find some other group for requesting e-books- www.squiffer.com This is a good reference for ebooks.Any more requests for uploading ebooks may result in a ban from the group. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri, Jun 8, 2012 at 7:05 PM, Decipher ankurseth...@gmail.com wrote: Does anybody has its ebook ? Please upload it -- 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/-/AETPnqJps7AJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Hemesh singh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Directi Question
On Jun 16, 2:1@shubham couldnt understand following logic in you algo please explain when first k elemnts traversed then traverse again k elemnts of B and S[2*k-i]+=B[i])...again S[i-2*k]+=B[i][.so on till B is traversed completely. 6 am, Shubham Sandeep s.shubhamsand...@gmail.com wrote: wat constraints does dis bring in the question... Also the books are arranged in a certain order and this order must never be changed. does this imply --- a student gets only consecutivly numbered book if not then sort the array B in decreasing order in Onlogn take another array S of k elements traverse B(sorted) S[i]=B[i] when first k elemnts traversed then traverse again k elemnts of B and S[2*k-i]+=B[i])...again S[i-2*k]+=B[i][.so on till B is traversed completely.. On Sat, Jun 16, 2012 at 2:22 AM, Hemesh Singh hemesh.mn...@gmail.comwrote: At first look it appears to be a simple problem of discrete binary search. Take sum of b[i] as the upper_bound and 0 as the lower bound. Then apply a simple binary search for the number of pages that can be given to a student. Complexity : O(N log( sum( B ) ) ) On Thu, Jun 14, 2012 at 12:26 PM, algogeek dayanidhi.haris...@gmail.comwrote: In a library there are N books with the number of pages in i th book given by bi . These books are to be distributed among K students such that the difference between the largest sum of pages in the books assigned to any student and the smallest sum of number of pages in the books assigned to any student is minimum for the given input. Also the books are arranged in a certain order and this order must never be changed. For eg: suppose B[ ] contains the number of pages in each book. then N=6 K=3 B={3,7,8,2,6,4} then the output will be 0 as we can give book 1 and 2 to student 1 and book 3 and 4 to student 2 and the remaining to student 3. That makes 10 pages for student 1 10 for 2 and 10 for 3 and thus the difference is 0 similarly if B={3,6,8,2,6,4} then the minimum difference will be 1 . -- 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/-/JjKITS_gN9UJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Hemesh singh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: No of tri-angles
@anmol my algo will work even if nos are not in ascending order .correct me if i am wrong. On Jun 15, 7:45 am, Amol Sharma amolsharm...@gmail.com wrote: sry ignore the last comment for i wanted to say - your algo will work only when the numbers given are consecutive. -- Amol Sharma Final Year Student Computer Science and Engineering MNNIT Allahabad http://gplus.to/amolsharma99 http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://www.simplyamol.blogspot.com/http://facebook.com/amolsharma99 On Fri, Jun 15, 2012 at 8:06 PM, Amol Sharma amolsharm...@gmail.com wrote: @enchantress : your algo will work only when the number given are positive. -- Amol Sharma Final Year Student Computer Science and Engineering MNNIT Allahabad http://gplus.to/amolsharma99 http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://www.simplyamol.blogspot.com/ On Fri, Jun 15, 2012 at 7:01 PM, shiv narayan narayan.shiv...@gmail.comwrote: this is the running code to find no of triangles using brute force technique logic: in a triangle having sides a,b,c; then a+bc(if c is greatest side) correct me if i am wrong. #includeiostream #includeconio.h using namespace std; int max(int a,int b,int c) { return ((ab?a:b)c?(ab?a:b):c); } int main() { int n,a[120],t,p,q; cint; while(t--) { cinn; for(int i=0;in;i++) cina[i]; int i,j,no_of_triangles=0,sum=0,largest_edge; for(i=0;in-2;i++) { for(j=i+2;jn;j++) { sum=a[i]+a[i+1]+a[j]; largest_edge=max(a[i],a[i+1],a[j]); if(sum-largest_edgelargest_edge) { no_of_triangles++; couta[i] a[i+1] a[j]\n;} } } coutno_of_trianglesendl; } getch(); return 0; } On Wednesday, 13 June 2012 22:18:01 UTC+5:30, payel roy wrote: Let's say there are N sides are given. Length of them are like 1,2,3,4,5,N. How do you determine how many tri-angles can be made out of these N sides? -- 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/-/WizMjfsoizsJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: No of tri-angles
@amol True, but the question suggests they are . If they arent then it'll require sorting the array and then binary search for largest index for which a[index] a[i]+a[j] .. Then required triangles are index-j for looped values i and j. On Friday, 15 June 2012 20:15:26 UTC+5:30, Amol Sharma wrote:sry ignore the last comment for i wanted to say - your algo will work only when the numbers given are consecutive. On Wednesday, 13 June 2012 22:18:01 UTC+5:30, payel roy wrote: Let's say there are N sides are given. Length of them are like 1,2,3,4,5,N. How do you determine how many tri-angles can be made out of these N sides? -- 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/-/kv8ysNreJt4J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.