Re: [algogeeks] Amazon Interview Question
we cant traverse the string twice... if there is an error in my logic then plz tell my logic is: we have to take starting and ending indexes for '0','1','2' like below 0 1 2 starting_index ending_index now suppose our string 102112011 so we start from the left and traverse the whole string first character ='1' 0 1 2 starting_index 0 ending_index 0 next character = '0' 0 1 2 starting_index 1 0 ending_index 1 0 ( ending_index0 ending_index1 ) so we swap the numbers according to Starting_index not according to Ending_index So it will become 0 1 2 starting_index 0 1 ending_index 0 1 and string will become 01 next character '2' 0 1 2 starting_index 0 1 2 ending_index 0 1 2 (ending_index0ending_index1ending_index2)so ending indexes in increasing order...so no need to swap so string is now 012 next character '1' 0 1 2 starting_index 0 1 2 ending_index 0 3 2 (ending_index1ending_index2) so we swap the current 1 with starting index of 2 so string will become 0112 0 1 2 starting_index 0 1 3 ending_index 0 2 3 next character '1' 0 1 2 starting_index 0 1 3 ending_index 0 4 3 (ending_index1ending_index2) so we swap the current 1 with starting index of 2 so string will become 01112 0 1 2 starting_index 0 1 4 ending_index 0 3 4 next character '2' 0 1 2 starting_index 0 1 4 ending_index 0 3 5 (ending_index0ending_index1ending_index2) so no swap so string will become 011122 next character '0' 0 1 2 starting_index 0 1 4 ending_index 6 3 5 (ending_index0ending_index1ending_index2) so we swap the current 0 with staring index of 2 first and then with starting index of 1 so string will become 0011122 0 1 2 starting_index 0 2 5 ending_index 1 4 6 and so on i hope its much explained... On Sat, Sep 24, 2011 at 10:30 AM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: char str[100],t; scanf(%s,str); char ch='0'; int i=0,j=0; while(jstrlen(str)) { if(str[j]==ch) { SWAP(str[i],str[j],t); i++; } j++; } ch='1'; j=i; while(jstrlen(str)) { if(str[j]==ch) { SWAP(str[i],str[j],t); i++; } j++; } printf(%s\n,str); On Sat, Sep 24, 2011 at 9:55 AM, Anup Ghatage ghat...@gmail.com wrote: Is this like the segregating all the 1's to the right and the 0's to the left or am i missing something? On Sat, Sep 24, 2011 at 9:39 AM, VIHARRI viharri@gmail.com wrote: You are given a string (consisting of 0's, 1's or 2's) where 0 represents a blue ball, 1 a red ball, and 2 a black ball. Using only swap operations (counting sort not allowed) rearrange the string such that all blue balls are together on one side, followed by all red balls, and then all black balls. You can iterate through the string only once. Eg 102112011 should produce 00122? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Anup Ghatage -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to
[algogeeks] Re: Amazon Interview Question
Here, can we use function for comparison ?? -- 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/-/ZgGYGAZwvcoJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] puzzle
Assume that you have just heard of a scandal and you are the first one to know. You pass it on to four person in a matter of 30 minutes. Each of these four in turn passes it to four other persons in the next 30 minutes and so on. How long it will take for everybody in the World to get to know the scandal? Assume that nobody hears it more than once and the population of the World is approximately 5.6 billions. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: puzzle
sum of GP.. a=1 common ratio=4 sum is given=5.6 billion.. find n simple enough -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: puzzle
^^ ans will be n*30 mins On Sep 24, 8:40 am, яαωαт Jee anuragrawat1...@gmail.com wrote: sum of GP.. a=1 common ratio=4 sum is given=5.6 billion.. find n simple enough -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] C++ Doubts !!
Q1) What does the compiler does if I declare a base class VIRTUAL ?? Q2) In the below test code , class A : public B, public C { }; The order of constructor invocation is : B C A but if C is virtual base class the it changes to : C B A Why ?? Q3) Write a macro that swaps any data given to it (Eg: char , int , pointer of any kind , float ) -- 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/-/mj25b-AYRgAJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Interview Question
i think this travels only once ... correct me if am wrong #includestdio.h #includestring.h #define SWAP(a,b,c) (c)=(a),(a)=(b),(b)=(c) int main() { int t,x; scanf(%d,t); while(t--) { char str[100]; scanf(%s,str); int i=0,j=0,k=strlen(str)-1; while(str[i]=='0') i++; while(str[k]=='2') k--; j=i; while(j=k) { if(str[j]=='2') { SWAP(str[j],str[k],x); k--; } if(str[j]=='0') { SWAP(str[i],str[j],x); i++; } if(str[j]!='2') j++; } printf(%s\n,str); } return 0; } On Sat, Sep 24, 2011 at 11:39 AM, Yogesh Yadav medu...@gmail.com wrote: we cant traverse the string twice... if there is an error in my logic then plz tell my logic is: we have to take starting and ending indexes for '0','1','2' like below 0 1 2 starting_index ending_index now suppose our string 102112011 so we start from the left and traverse the whole string first character ='1' 0 1 2 starting_index 0 ending_index 0 next character = '0' 0 1 2 starting_index 1 0 ending_index 1 0 ( ending_index0 ending_index1 ) so we swap the numbers according to Starting_index not according to Ending_index So it will become 0 1 2 starting_index 0 1 ending_index 0 1 and string will become 01 next character '2' 0 1 2 starting_index 0 1 2 ending_index 0 1 2 (ending_index0ending_index1ending_index2)so ending indexes in increasing order...so no need to swap so string is now 012 next character '1' 0 1 2 starting_index 0 1 2 ending_index 0 3 2 (ending_index1ending_index2) so we swap the current 1 with starting index of 2 so string will become 0112 0 1 2 starting_index 0 1 3 ending_index 0 2 3 next character '1' 0 1 2 starting_index 0 1 3 ending_index 0 4 3 (ending_index1ending_index2) so we swap the current 1 with starting index of 2 so string will become 01112 0 1 2 starting_index 0 1 4 ending_index 0 3 4 next character '2' 0 1 2 starting_index 0 1 4 ending_index 0 3 5 (ending_index0ending_index1ending_index2) so no swap so string will become 011122 next character '0' 0 1 2 starting_index 0 1 4 ending_index 6 3 5 (ending_index0ending_index1ending_index2) so we swap the current 0 with staring index of 2 first and then with starting index of 1 so string will become 0011122 0 1 2 starting_index 0 2 5 ending_index 1 4 6 and so on i hope its much explained... On Sat, Sep 24, 2011 at 10:30 AM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: char str[100],t; scanf(%s,str); char ch='0'; int i=0,j=0; while(jstrlen(str)) { if(str[j]==ch) { SWAP(str[i],str[j],t); i++; } j++; } ch='1'; j=i; while(jstrlen(str)) { if(str[j]==ch) { SWAP(str[i],str[j],t); i++; } j++; } printf(%s\n,str);
Re: [algogeeks] Amazon Interview Question
dutch national flag problem :) On Sat, Sep 24, 2011 at 3:45 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: i think this travels only once ... correct me if am wrong #includestdio.h #includestring.h #define SWAP(a,b,c) (c)=(a),(a)=(b),(b)=(c) int main() { int t,x; scanf(%d,t); while(t--) { char str[100]; scanf(%s,str); int i=0,j=0,k=strlen(str)-1; while(str[i]=='0') i++; while(str[k]=='2') k--; j=i; while(j=k) { if(str[j]=='2') { SWAP(str[j],str[k],x); k--; } if(str[j]=='0') { SWAP(str[i],str[j],x); i++; } if(str[j]!='2') j++; } printf(%s\n,str); } return 0; } On Sat, Sep 24, 2011 at 11:39 AM, Yogesh Yadav medu...@gmail.com wrote: we cant traverse the string twice... if there is an error in my logic then plz tell my logic is: we have to take starting and ending indexes for '0','1','2' like below 0 1 2 starting_index ending_index now suppose our string 102112011 so we start from the left and traverse the whole string first character ='1' 0 1 2 starting_index 0 ending_index 0 next character = '0' 0 1 2 starting_index 1 0 ending_index 1 0 ( ending_index0 ending_index1 ) so we swap the numbers according to Starting_index not according to Ending_index So it will become 0 1 2 starting_index 0 1 ending_index 0 1 and string will become 01 next character '2' 0 1 2 starting_index 0 1 2 ending_index 0 1 2 (ending_index0ending_index1ending_index2)so ending indexes in increasing order...so no need to swap so string is now 012 next character '1' 0 1 2 starting_index 0 1 2 ending_index 0 3 2 (ending_index1ending_index2) so we swap the current 1 with starting index of 2 so string will become 0112 0 1 2 starting_index 0 1 3 ending_index 0 2 3 next character '1' 0 1 2 starting_index 0 1 3 ending_index 0 4 3 (ending_index1ending_index2) so we swap the current 1 with starting index of 2 so string will become 01112 0 1 2 starting_index 0 1 4 ending_index 0 3 4 next character '2' 0 1 2 starting_index 0 1 4 ending_index 0 3 5 (ending_index0ending_index1ending_index2) so no swap so string will become 011122 next character '0' 0 1 2 starting_index 0 1 4 ending_index 6 3 5 (ending_index0ending_index1ending_index2) so we swap the current 0 with staring index of 2 first and then with starting index of 1 so string will become 0011122 0 1 2 starting_index 0 2 5 ending_index 1 4 6 and so on i hope its much explained... On Sat, Sep 24, 2011 at 10:30 AM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: char str[100],t; scanf(%s,str); char ch='0'; int i=0,j=0; while(jstrlen(str)) { if(str[j]==ch) { SWAP(str[i],str[j],t); i++; } j++; } ch='1'; j=i; while(jstrlen(str)) { if(str[j]==ch) { SWAP(str[i],str[j],t);
Re: [algogeeks] Re: Adobe final interview question : small change
Can you please explain. I dont know about design patterns. Also please share some good book for design patterns. thanks On Fri, Sep 23, 2011 at 4:07 PM, Prem Krishna Chettri hprem...@gmail.comwrote: This is Simple query related to Factory Design Pattern... Have a look at the Auto Registration of Factory Design pattern.. :) Prem On Fri, Sep 23, 2011 at 3:02 PM, algo geek geeka...@gmail.com wrote: You have a library provided by the vendor. All you have is header files and library files. Library contains the class Shape and there is whole hierarchy tree (i mean classes which derive from this base class). Now you want to add some function getArea (not originally present in the class or any of its derived class) in the class Shape , you dont have the source code. Using this library, you have written a lot of code. Now you have to make some changes so that, any object of Shape class (or its derived class) will be able to call this function. With your strategy, you should be able to override the definition of this function in the derived class. I think it is related to design patterns, not sure. I gave the solution that : we will use MyShape , and use composition. i.e. will create the object of Shape class inside this NewShape class and interface can be made. Internally, we can call the functions of Shape object. That will work fine. But we have to do this for the whole design hierarchy. Secondly, if there is some changes by the vendor in future in the library, i have to change my new design tree. e.g. class Shape { public : void draw(); void clear(); } class Circle : public Shape{ public : void draw(); void clear(); } class Rectangle: public Shape{ public : void draw(); void clear(); } class NewShape{ private Shape * obj; public : void draw(){ obj-draw(); } void clear() { obj-clear(); } int getArear(){ //implementtation of getArea function } } class NewCircle : NewShape{ public : void draw(){ (Circle*)obj-draw(); } void clear() { (Circle*)obj-clear(); } int getArear(){ //implementtation of getArea function specific to circle } } class NewRectangle : NewShape{ public : void draw(){ (Rectangle*)obj-draw(); } void clear() { (Rctangle*)obj-clear(); } int getArear(){ //implementtation of getArea function } } I know this solution is not good.. please provide a better approach for this. Please let me knw if anything is not clear. Thanks in advance. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: AMDOCS
Has Amdocs been to other colleges in this Semester Any information about it would be highly appreciated. On Sep 23, 9:16 am, aayush jain ajain...@gmail.com wrote: can anybody tell me the pattern of amdocs written test and interview qus. its urgent so plz -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] BST in file
I need to print a binary search tree in file. When I will retrieve the same tree from the file. I have thought about printing in xml format like this 100 / \ 50 150 / \ / \ 30 70 120 200 Level 0 100 Level 1 50 Level 2 30 /Level2 Level 2 70 /Level 2 /Level 1 Level 1 150 Level 2 120 /Level 2 Level 2 200 /level 2 /level 1 /level 0 I don't know will this be the best solution or not. Please suggest me how to approach it or some better solution. Regards Asit http://kodeyard.blogspot.com/ -- 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/-/3jOjGyT3F-kJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Can anyone tell amazon written questions ??? thanx in adv.
anyone? On Sat, Sep 17, 2011 at 5:54 AM, Deoki Nandan deok...@gmail.com wrote: -- **With Regards Deoki Nandan Vishwakarma * * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: puzzle
GP 2011/9/24 яαωαт Jee anuragrawat1...@gmail.com ^^ ans will be n*30 mins On Sep 24, 8:40 am, яαωαт Jee anuragrawat1...@gmail.com wrote: sum of GP.. a=1 common ratio=4 sum is given=5.6 billion.. find n simple enough -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Interview Question
I think this will do the same: - #include stdafx.h #include stdlib.h void swap(int *a, int start, int end) { int temp; temp = *(a + start); *(a + start) = *(a + end); *(a + end) = temp; } int _tmain(int argc, _TCHAR* argv[]) { int minIndex=0, maxIndex=8; int i=1; int a[9] ={1,0,2,1,0,2,0,0,1}; while(imaxIndex) { if(a[maxIndex] == 2) maxIndex--; if(a[minIndex] == 0) minIndex++; if(a[i] a[maxIndex]) { swap(a, i, maxIndex); continue; } else if (a[i] a[minIndex]) { swap(a, i, minIndex); continue; } i++; } for (i =0 ; i 9; i++) printf([%d], a[i]); system(PAUSE); return 0; } Please comment. Cheers, Ankit Sinha On Sat, Sep 24, 2011 at 4:10 PM, malay chakrabarti m1234...@gmail.com wrote: dutch national flag problem :) On Sat, Sep 24, 2011 at 3:45 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: i think this travels only once ... correct me if am wrong #includestdio.h #includestring.h #define SWAP(a,b,c) (c)=(a),(a)=(b),(b)=(c) int main() { int t,x; scanf(%d,t); while(t--) { char str[100]; scanf(%s,str); int i=0,j=0,k=strlen(str)-1; while(str[i]=='0') i++; while(str[k]=='2') k--; j=i; while(j=k) { if(str[j]=='2') { SWAP(str[j],str[k],x); k--; } if(str[j]=='0') { SWAP(str[i],str[j],x); i++; } if(str[j]!='2') j++; } printf(%s\n,str); } return 0; } On Sat, Sep 24, 2011 at 11:39 AM, Yogesh Yadav medu...@gmail.com wrote: we cant traverse the string twice... if there is an error in my logic then plz tell my logic is: we have to take starting and ending indexes for '0','1','2' like below 0 1 2 starting_index ending_index now suppose our string 102112011 so we start from the left and traverse the whole string first character ='1' 0 1 2 starting_index 0 ending_index 0 next character = '0' 0 1 2 starting_index 1 0 ending_index 1 0 ( ending_index0 ending_index1 ) so we swap the numbers according to Starting_index not according to Ending_index So it will become 0 1 2 starting_index 0 1 ending_index 0 1 and string will become 01 next character '2' 0 1 2 starting_index 0 1 2 ending_index 0 1 2 (ending_index0ending_index1ending_index2) so ending indexes in increasing order...so no need to swap so string is now 012 next character '1' 0 1 2 starting_index 0 1 2 ending_index 0 3 2 (ending_index1ending_index2) so we swap the current 1 with starting index of 2 so string will become 0112 0 1 2 starting_index 0 1 3 ending_index 0 2 3 next character '1' 0 1 2 starting_index 0 1 3 ending_index 0 4 3 (ending_index1ending_index2) so we swap the current 1 with starting index of 2 so string will become 01112 0 1 2 starting_index 0 1 4 ending_index 0 3 4 next character '2' 0 1 2 starting_index 0 1 4 ending_index 0 3 5 (ending_index0ending_index1ending_index2) so no swap so string will become 011122 next character '0' 0 1 2 starting_index 0 1 4 ending_index 6 3 5 (ending_index0ending_index1ending_index2) so we swap the current 0 with
Re: [algogeeks] Amazon Interview Question
void sort012(int a[],int n){ int i = 0, s = 0, last = n-1; while(i=last){ if(a[i] == 0 i!=s) { swap(a[i], a[s]); s++; } else if(a[i] == 2 i!=last) { swap(a[i], a[last]); last--; } else i++; } } On Sat, Sep 24, 2011 at 5:13 PM, Ankit Sinha akki12...@gmail.com wrote: I think this will do the same: - #include stdafx.h #include stdlib.h void swap(int *a, int start, int end) { int temp; temp = *(a + start); *(a + start) = *(a + end); *(a + end) = temp; } int _tmain(int argc, _TCHAR* argv[]) { int minIndex=0, maxIndex=8; int i=1; int a[9] ={1,0,2,1,0,2,0,0,1}; while(imaxIndex) { if(a[maxIndex] == 2) maxIndex--; if(a[minIndex] == 0) minIndex++; if(a[i] a[maxIndex]) { swap(a, i, maxIndex); continue; } else if (a[i] a[minIndex]) { swap(a, i, minIndex); continue; } i++; } for (i =0 ; i 9; i++) printf([%d], a[i]); system(PAUSE); return 0; } Please comment. Cheers, Ankit Sinha On Sat, Sep 24, 2011 at 4:10 PM, malay chakrabarti m1234...@gmail.com wrote: dutch national flag problem :) On Sat, Sep 24, 2011 at 3:45 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: i think this travels only once ... correct me if am wrong #includestdio.h #includestring.h #define SWAP(a,b,c) (c)=(a),(a)=(b),(b)=(c) int main() { int t,x; scanf(%d,t); while(t--) { char str[100]; scanf(%s,str); int i=0,j=0,k=strlen(str)-1; while(str[i]=='0') i++; while(str[k]=='2') k--; j=i; while(j=k) { if(str[j]=='2') { SWAP(str[j],str[k],x); k--; } if(str[j]=='0') { SWAP(str[i],str[j],x); i++; } if(str[j]!='2') j++; } printf(%s\n,str); } return 0; } On Sat, Sep 24, 2011 at 11:39 AM, Yogesh Yadav medu...@gmail.com wrote: we cant traverse the string twice... if there is an error in my logic then plz tell my logic is: we have to take starting and ending indexes for '0','1','2' like below 0 1 2 starting_index ending_index now suppose our string 102112011 so we start from the left and traverse the whole string first character ='1' 0 1 2 starting_index 0 ending_index 0 next character = '0' 0 1 2 starting_index 1 0 ending_index 1 0 ( ending_index0 ending_index1 ) so we swap the numbers according to Starting_index not according to Ending_index So it will become 0 1 2 starting_index 0 1 ending_index 0 1 and string will become 01 next character '2' 0 1 2 starting_index 0 1 2 ending_index 0 1 2 (ending_index0ending_index1ending_index2)so ending indexes in increasing order...so no need to swap so string is now 012 next character '1' 0 1 2 starting_index 0 1 2 ending_index 0 3 2 (ending_index1ending_index2) so we swap the current 1 with starting index of 2 so string will become 0112 0 1 2 starting_index 0 1 3 ending_index 0 2 3 next character '1' 0 1 2 starting_index 0 1 3 ending_index 0 4 3 (ending_index1ending_index2) so we swap the current 1 with starting index of 2 so string will become 01112 0 1 2 starting_index 0 1 4 ending_index 0 3 4 next character '2'
Re: [algogeeks] Amazon Interview Question
Classic problem http://en.wikipedia.org/wiki/Dutch_national_flag_problem On Sat, Sep 24, 2011 at 5:15 PM, Ankur Garg ankurga...@gmail.com wrote: void sort012(int a[],int n){ int i = 0, s = 0, last = n-1; while(i=last){ if(a[i] == 0 i!=s) { swap(a[i], a[s]); s++; } else if(a[i] == 2 i!=last) { swap(a[i], a[last]); last--; } else i++; } } On Sat, Sep 24, 2011 at 5:13 PM, Ankit Sinha akki12...@gmail.com wrote: I think this will do the same: - #include stdafx.h #include stdlib.h void swap(int *a, int start, int end) { int temp; temp = *(a + start); *(a + start) = *(a + end); *(a + end) = temp; } int _tmain(int argc, _TCHAR* argv[]) { int minIndex=0, maxIndex=8; int i=1; int a[9] ={1,0,2,1,0,2,0,0,1}; while(imaxIndex) { if(a[maxIndex] == 2) maxIndex--; if(a[minIndex] == 0) minIndex++; if(a[i] a[maxIndex]) { swap(a, i, maxIndex); continue; } else if (a[i] a[minIndex]) { swap(a, i, minIndex); continue; } i++; } for (i =0 ; i 9; i++) printf([%d], a[i]); system(PAUSE); return 0; } Please comment. Cheers, Ankit Sinha On Sat, Sep 24, 2011 at 4:10 PM, malay chakrabarti m1234...@gmail.com wrote: dutch national flag problem :) On Sat, Sep 24, 2011 at 3:45 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: i think this travels only once ... correct me if am wrong #includestdio.h #includestring.h #define SWAP(a,b,c) (c)=(a),(a)=(b),(b)=(c) int main() { int t,x; scanf(%d,t); while(t--) { char str[100]; scanf(%s,str); int i=0,j=0,k=strlen(str)-1; while(str[i]=='0') i++; while(str[k]=='2') k--; j=i; while(j=k) { if(str[j]=='2') { SWAP(str[j],str[k],x); k--; } if(str[j]=='0') { SWAP(str[i],str[j],x); i++; } if(str[j]!='2') j++; } printf(%s\n,str); } return 0; } On Sat, Sep 24, 2011 at 11:39 AM, Yogesh Yadav medu...@gmail.com wrote: we cant traverse the string twice... if there is an error in my logic then plz tell my logic is: we have to take starting and ending indexes for '0','1','2' like below 0 1 2 starting_index ending_index now suppose our string 102112011 so we start from the left and traverse the whole string first character ='1' 0 1 2 starting_index 0 ending_index 0 next character = '0' 0 1 2 starting_index 1 0 ending_index 1 0 ( ending_index0 ending_index1 ) so we swap the numbers according to Starting_index not according to Ending_index So it will become 0 1 2 starting_index 0 1 ending_index 0 1 and string will become 01 next character '2' 0 1 2 starting_index 0 1 2 ending_index 0 1 2 (ending_index0ending_index1ending_index2)so ending indexes in increasing order...so no need to swap so string is now 012 next character '1' 0 1 2 starting_index 0 1 2 ending_index 0 3 2 (ending_index1ending_index2) so we swap the current 1 with starting index of 2 so string will become 0112 0 1 2 starting_index 0 1 3 ending_index 0 2 3 next character '1' 0 1 2 starting_index 0 1 3 ending_index 0 4 3 (ending_index1ending_index2) so we swap the current 1 with starting index of 2 so string will become 01112
Re: [algogeeks] help nedded
for 1st #includeiostream #includevector using namespace std; int main() { char c; string s; int n; vector char ans; cins; int i=0; while(s[i]!='\0') { c=s[i]; n=s[i+1]-'0'; while(n--) ans.push_back(c); i+=2; } for(i=0;ians.size();i++) coutans[i]; return 0; } On Thu, Sep 22, 2011 at 3:46 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: for 1st #includeiostream #includeconio.h #includestring.h using namespace std; int main() { char str[100]; cinstr; int len=strlen(str); int i=1; while(ilen) { int x=str[i]-48; while(x--) coutstr[i-1]; i+=2; } getch(); } On Thu, Sep 22, 2011 at 3:42 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: for 2nd one #includeiostream #includeconio.h using namespace std; int main() { char str[100]; cinstr; char ch=str[0]; int count=0,i=0; while(str[i]) { if(str[i]==ch) count++; else { coutchcount; ch=str[i]; count=1; } i++; } coutchcount; getch(); } On Thu, Sep 22, 2011 at 11:58 AM, rahul sharma rahul23111...@gmail.comwrote: i found a question of ms earlier but know i not able to find it.plz post link or thread i/p::a3b2c4: o/p:aaabb i/p:aaabbc o/p:a3b2c1 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Kunal Yadav (http://sourcebit.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.
Re: [algogeeks] help nedded
2nd #includeiostream #includevector using namespace std; int main() { string s; cins; int i=0,count=1; vectorint no; vectorchar c; while(s[i]!='\0') { if(s[i]==s[i+1]) count++; else { c.push_back(s[i]); no.push_back(count); count=1; } i++; } for(i=0;ic.size();i++) coutc[i]no[i]; return 0; } On Sat, Sep 24, 2011 at 5:53 PM, Kunal Yadav kunalyada...@gmail.com wrote: for 1st #includeiostream #includevector using namespace std; int main() { char c; string s; int n; vector char ans; cins; int i=0; while(s[i]!='\0') { c=s[i]; n=s[i+1]-'0'; while(n--) ans.push_back(c); i+=2; } for(i=0;ians.size();i++) coutans[i]; return 0; } On Thu, Sep 22, 2011 at 3:46 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: for 1st #includeiostream #includeconio.h #includestring.h using namespace std; int main() { char str[100]; cinstr; int len=strlen(str); int i=1; while(ilen) { int x=str[i]-48; while(x--) coutstr[i-1]; i+=2; } getch(); } On Thu, Sep 22, 2011 at 3:42 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: for 2nd one #includeiostream #includeconio.h using namespace std; int main() { char str[100]; cinstr; char ch=str[0]; int count=0,i=0; while(str[i]) { if(str[i]==ch) count++; else { coutchcount; ch=str[i]; count=1; } i++; } coutchcount; getch(); } On Thu, Sep 22, 2011 at 11:58 AM, rahul sharma rahul23111...@gmail.comwrote: i found a question of ms earlier but know i not able to find it.plz post link or thread i/p::a3b2c4: o/p:aaabb i/p:aaabbc o/p:a3b2c1 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Kunal Yadav (http://sourcebit.in) -- Regards Kunal Yadav (http://sourcebit.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.
[algogeeks] Re: BST in file
you can put two traversals of three (inorder, preorder or postorder) in the file.. Two traversals are enough to dedicate a particular tree. On Sep 24, 4:05 pm, Asit Dhal lipu...@gmail.com wrote: I need to print a binary search tree in file. When I will retrieve the same tree from the file. I have thought about printing in xml format like this 100 / \ 50 150 / \ / \ 30 70 120 200 Level 0 100 Level 1 50 Level 2 30 /Level2 Level 2 70 /Level 2 /Level 1 Level 1 150 Level 2 120 /Level 2 Level 2 200 /level 2 /level 1 /level 0 I don't know will this be the best solution or not. Please suggest me how to approach it or some better solution. Regards Asithttp://kodeyard.blogspot.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.
Re: [algogeeks] Re: Amazon online test
shiv narayan: your answer is correct On 24 September 2011 11:12, shiv narayan narayan.shiv...@gmail.com wrote: what is answer to In how many ways 3 identical coins can be placed in 5x5 grid so that no two coin come in same row and same column ?? according to me it should be 25*16*9 . On Sep 24, 2:19 am, Deoki Nandan deok...@gmail.com wrote: 1)write code to find first non repeating character in given string 2)write code for image of binary tree 3)swap adjacent nodes of given linked list using one pointer 4)find pair of number in given array whose sum is given 5)write BST(Binary Search Tree) into file and read from file there were 25 MCQ questions as well like 1)In how many ways 3 identical coins can be placed in 5x5 grid so that no two coin come in same row and same column 2)there is an array of length n having numbers from 1-10 . what is the probability to choose a number and chosen number is 10 3)one question on average waiting time of preemptive SJF scheduling algorithm 4)what will happen of child process if parent is killed 5)print value of present directory using UNIX command (my ans is $pwd | echo )correct me if I'm wrong other I don't remember On 23 September 2011 17:39, siddharth srivastava akssps...@gmail.com wrote: Hi On 23 September 2011 17:29, raju nikutel...@gmail.com wrote: hi all, can anyone pls share the questions amazon has been asking in online written tests. Search the archives This has been answered many times in the recent days. Best of Luck thanks raju -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Siddharth Srivastava -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **With Regards Deoki Nandan Vishwakarma * * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **With Regards Deoki Nandan Vishwakarma * * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 online test
@shiv : Correct Answer should be : 5C3 X 5 X 4 X3 = 600 Aamir Khan | 3rd Year | Computer Science Engineering | IIT 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.
Re: [algogeeks] Re: Amazon online test
Deoki nandan In MCQ there were options as well ?? is it ? Also were questions in MCQ only from coding or OOPS,DBMS,OS etc also are part of those ? Regards On Sat, Sep 24, 2011 at 6:13 PM, Aamir Khan ak4u2...@gmail.com wrote: @shiv : Correct Answer should be : 5C3 X 5 X 4 X3 = 600 Aamir Khan | 3rd Year | Computer Science Engineering | IIT 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] EMC^2
does any one have the idea about emc2 .?? if yes plz do share the details -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Sorting:-
What is the efficient way to sort a M*N matrix. eg: Given a 3*4 matrix 2 6 7 12 11 8 5 1 9 3 4 10 The ouput should be 1 2 3 4 5 6 7 8 9 10 11 12 Matrix may contain duplicates.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] sqrt function...
any one suggest an algo to write own sqrt func...?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: sqrt function...
//bakhshali approximation for calculating square root /* S=number for which squareroot is reqd. N=nearest perfect square d=S-N*N; //difference P=d/(2*N) A=N+P; ans=A-(p*P)/(2*A) */ #includestdio.h #includeconio.h void main(){ float S; float P,A,d,ans; int N; printf(Enter number whose sqrt is reqd:); scanf(%f,S); N=check_nearest_perfect_sqre(S); d=S-N*N; P=d/(2*N); A=N+P; ans=A-(P*P)/(2*A); printf(Squareroot of %f is %f,S,ans); getch(); int check_nearest_perfect_sqre(double square) { int i=0; while((i*i)square) i++; return i; } } -- 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/-/Qt_tVimFYFUJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: sqrt function...
http://www.geeksforgeeks.org/archives/3187 check dis one. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: THANX ALGOGEEKS !!!!!!
congrats buddy On 23 September 2011 17:31, siddharth srivastava akssps...@gmail.comwrote: Hi Congrats What did you answer for elevator problem ? On 22 September 2011 18:42, saurabh sah.saurab...@gmail.com wrote: thanx to all I have shared my interview experience at http://msidcinterview.blogspot.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 Siddharth Srivastava -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **With Regards Deoki Nandan Vishwakarma * * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Interview Question
Keep two pointers - p1 and p2 p1 points at the index just after last 0 such that there are all zero's before it. p2 points at the entry just before last 2, and there are all 2's after it. *example*- 0010201201222 p1 = 2; p2 = 9; *Pseudo code - * p1 = 0; p2 = n-1; i = 0; while(in) if(A[i]) ==0) swap(p1,i); p1++; else if (A[i]==1) i++; else if(A[i]==2) swap (p2,i); p2--; On Sat, Sep 24, 2011 at 11:39 AM, Yogesh Yadav medu...@gmail.com wrote: we cant traverse the string twice... if there is an error in my logic then plz tell my logic is: we have to take starting and ending indexes for '0','1','2' like below 0 1 2 starting_index ending_index now suppose our string 102112011 so we start from the left and traverse the whole string first character ='1' 0 1 2 starting_index 0 ending_index 0 next character = '0' 0 1 2 starting_index 1 0 ending_index 1 0 ( ending_index0 ending_index1 ) so we swap the numbers according to Starting_index not according to Ending_index So it will become 0 1 2 starting_index 0 1 ending_index 0 1 and string will become 01 next character '2' 0 1 2 starting_index 0 1 2 ending_index 0 1 2 (ending_index0ending_index1ending_index2)so ending indexes in increasing order...so no need to swap so string is now 012 next character '1' 0 1 2 starting_index 0 1 2 ending_index 0 3 2 (ending_index1ending_index2) so we swap the current 1 with starting index of 2 so string will become 0112 0 1 2 starting_index 0 1 3 ending_index 0 2 3 next character '1' 0 1 2 starting_index 0 1 3 ending_index 0 4 3 (ending_index1ending_index2) so we swap the current 1 with starting index of 2 so string will become 01112 0 1 2 starting_index 0 1 4 ending_index 0 3 4 next character '2' 0 1 2 starting_index 0 1 4 ending_index 0 3 5 (ending_index0ending_index1ending_index2) so no swap so string will become 011122 next character '0' 0 1 2 starting_index 0 1 4 ending_index 6 3 5 (ending_index0ending_index1ending_index2) so we swap the current 0 with staring index of 2 first and then with starting index of 1 so string will become 0011122 0 1 2 starting_index 0 2 5 ending_index 1 4 6 and so on i hope its much explained... On Sat, Sep 24, 2011 at 10:30 AM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: char str[100],t; scanf(%s,str); char ch='0'; int i=0,j=0; while(jstrlen(str)) { if(str[j]==ch) { SWAP(str[i],str[j],t); i++; } j++; } ch='1'; j=i; while(jstrlen(str)) { if(str[j]==ch) { SWAP(str[i],str[j],t); i++; } j++; } printf(%s\n,str); On Sat, Sep 24, 2011 at 9:55 AM, Anup Ghatage ghat...@gmail.com wrote: Is this like the segregating all the 1's to the right and the 0's to the left or am i missing something? On Sat, Sep 24, 2011 at 9:39 AM, VIHARRI viharri@gmail.com wrote: You are given a string (consisting of 0's, 1's or 2's) where 0 represents a blue ball, 1 a red ball, and 2 a black ball. Using only swap operations (counting sort not allowed) rearrange the string such that all blue balls are together on one side, followed by all red balls, and then all black balls. You can iterate through the string only once. Eg 102112011 should
[algogeeks] Re: BST in file
You can put the array representation of binary tree directly, with some obvious modifications ofcourse :) On Sep 24, 5:38 pm, asdqwe ayushgoel...@gmail.com wrote: you can put two traversals of three (inorder, preorder or postorder) in the file.. Two traversals are enough to dedicate a particular tree. On Sep 24, 4:05 pm, Asit Dhal lipu...@gmail.com wrote: I need to print a binary search tree in file. When I will retrieve the same tree from the file. I have thought about printing in xml format like this 100 / \ 50 150 / \ / \ 30 70 120 200 Level 0 100 Level 1 50 Level 2 30 /Level2 Level 2 70 /Level 2 /Level 1 Level 1 150 Level 2 120 /Level 2 Level 2 200 /level 2 /level 1 /level 0 I don't know will this be the best solution or not. Please suggest me how to approach it or some better solution. Regards Asithttp://kodeyard.blogspot.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.
Re: [algogeeks] Amazon Interview Question
@guarav true @others no point in sending the code describe your logic... anyway link provided by guarav is suffice to solve the problem On Sat, Sep 24, 2011 at 5:26 PM, Gaurav Aggarwal gaurav91.2...@gmail.comwrote: Classic problem http://en.wikipedia.org/wiki/Dutch_national_flag_problem On Sat, Sep 24, 2011 at 5:15 PM, Ankur Garg ankurga...@gmail.com wrote: void sort012(int a[],int n){ int i = 0, s = 0, last = n-1; while(i=last){ if(a[i] == 0 i!=s) { swap(a[i], a[s]); s++; } else if(a[i] == 2 i!=last) { swap(a[i], a[last]); last--; } else i++; } } On Sat, Sep 24, 2011 at 5:13 PM, Ankit Sinha akki12...@gmail.com wrote: I think this will do the same: - #include stdafx.h #include stdlib.h void swap(int *a, int start, int end) { int temp; temp = *(a + start); *(a + start) = *(a + end); *(a + end) = temp; } int _tmain(int argc, _TCHAR* argv[]) { int minIndex=0, maxIndex=8; int i=1; int a[9] ={1,0,2,1,0,2,0,0,1}; while(imaxIndex) { if(a[maxIndex] == 2) maxIndex--; if(a[minIndex] == 0) minIndex++; if(a[i] a[maxIndex]) { swap(a, i, maxIndex); continue; } else if (a[i] a[minIndex]) { swap(a, i, minIndex); continue; } i++; } for (i =0 ; i 9; i++) printf([%d], a[i]); system(PAUSE); return 0; } Please comment. Cheers, Ankit Sinha On Sat, Sep 24, 2011 at 4:10 PM, malay chakrabarti m1234...@gmail.com wrote: dutch national flag problem :) On Sat, Sep 24, 2011 at 3:45 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: i think this travels only once ... correct me if am wrong #includestdio.h #includestring.h #define SWAP(a,b,c) (c)=(a),(a)=(b),(b)=(c) int main() { int t,x; scanf(%d,t); while(t--) { char str[100]; scanf(%s,str); int i=0,j=0,k=strlen(str)-1; while(str[i]=='0') i++; while(str[k]=='2') k--; j=i; while(j=k) { if(str[j]=='2') { SWAP(str[j],str[k],x); k--; } if(str[j]=='0') { SWAP(str[i],str[j],x); i++; } if(str[j]!='2') j++; } printf(%s\n,str); } return 0; } On Sat, Sep 24, 2011 at 11:39 AM, Yogesh Yadav medu...@gmail.com wrote: we cant traverse the string twice... if there is an error in my logic then plz tell my logic is: we have to take starting and ending indexes for '0','1','2' like below 0 1 2 starting_index ending_index now suppose our string 102112011 so we start from the left and traverse the whole string first character ='1' 0 1 2 starting_index 0 ending_index 0 next character = '0' 0 1 2 starting_index 1 0 ending_index 1 0 ( ending_index0 ending_index1 ) so we swap the numbers according to Starting_index not according to Ending_index So it will become 0 1 2 starting_index 0 1 ending_index 0 1 and string will become 01 next character '2' 0 1 2 starting_index 0 1 2 ending_index 0 1 2 (ending_index0ending_index1ending_index2)so ending indexes in increasing order...so no need to swap so string is now 012 next character '1' 0 1 2 starting_index 0 1 2 ending_index 0 3 2 (ending_index1ending_index2) so we swap the current 1 with starting index of 2 so string will become 0112 0 1 2 starting_index 0 1 3 ending_index 0 2 3 next character '1' 0 1
[algogeeks] Re: EMC^2
Total Rounds: max 3. 1 written + 1 tech + 1 hr Probably there might be a 2nd tech interview in case they are willing to take you for the company and want to give you another chance to prove yourself. Tomorrow itself they'll complete the recruitment process and shortlist the candidates. Round 1: Written Test: mostly only general aptitude questions. since the offer is increased, they might ask technical questions. in technical test: mostly C, C++ ( 5 percent chance). and java very very rare.. Based on the number of students short listed after the first round, they would recruit only 1/3rd of the count. Round 2: Technical. There will be three or more types of panels depending on the number of people to be recruited. The panel that you might be called for is purely random and based on the L U C K factor. One panel might have pure coding where in full C and Data Structure questions will be asked. Another panel might ask general theoretical questions from all areas - networks, dbms, oops, c, data structures, etc... even puzzles. The other panel would ask questions only from the area of interest that you specify. Please put in the area which you are strongest at. All possible questions will be asked from your area of interest. HR Round: General as usual questions only. Mostly if you clear the technical rounds, then HR is chumma... namesake. U will be recruited :) :) Some details about the company: Basically a storage management company Core work: RAID groups, storage solutions for other clients. Also working on virtualization (virtual servers) and now moving towards cloud computing ALL THE BEST :) :) On Sep 24, 6:46 pm, aditya kumar aditya.kumar130...@gmail.com wrote: does any one have the idea about emc2 .?? if yes plz do share the details -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Doubt in templates
Hi I have written a simple template class. #include iostream using namespace std; template class T class vector { T *arr; int size; public: vector(int len) { arr = new T[size=len]; for(int i=0;ilen;i++) arr[i]=0; } vector(T *list) { for(int i=0;isize;i++) arr[i]=list[i]; } T operator *(vector obj) { T sum=0; for(int i=0;isize;i++) sum+=this-arr[i]*obj.arr[i]; return sum; } }; int main() { vector intv1(3); vector floatv2(3); int arr1[]={1,2,3}; float arr2[]={1.1,2.2,3.3}; v1=arr1; v2=arr2; float prod = v1*v2; //coutprod; return 0; } But on compiling it C++ gives error as error C2679: binary '*' : no operator found which takes a right-hand operand of type 'vectorT' (or there is no acceptable conversion) with [ T=float ] could be 'int vectorT::operator *(vectorT )' with [ T=int ] while trying to match the argument list '(vectorT, vectorT)' with [ T=int ] and [ T=float ] Is it because compiler could not find a way to convert from either float to int or vice versa or something else? Also what is the solution of this -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: sqrt function...
one of the simplest way is to do binary search... :) On Sat, Sep 24, 2011 at 8:42 PM, teja bala pawanjalsa.t...@gmail.comwrote: http://www.geeksforgeeks.org/archives/3187 check dis one. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: sqrt function...
On 24 September 2011 13:45, shady sinv...@gmail.com wrote: one of the simplest way is to do binary search... :) +1 On Sat, Sep 24, 2011 at 8:42 PM, teja bala pawanjalsa.t...@gmail.comwrote: http://www.geeksforgeeks.org/archives/3187 check dis one. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Siddharth Srivastava -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Sorting:-
is there any algo better than bruteforce for this : O(m*n*log(m*n)) On Sat, Sep 24, 2011 at 7:56 PM, teja bala pawanjalsa.t...@gmail.comwrote: What is the efficient way to sort a M*N matrix. eg: Given a 3*4 matrix 2 6 7 12 11 8 5 1 9 3 4 10 The ouput should be 1 2 3 4 5 6 7 8 9 10 11 12 Matrix may contain duplicates.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Sorting:-
Is the range of numbers provided ? On 24 September 2011 10:26, teja bala pawanjalsa.t...@gmail.com wrote: What is the efficient way to sort a M*N matrix. eg: Given a 3*4 matrix 2 6 7 12 11 8 5 1 9 3 4 10 The ouput should be 1 2 3 4 5 6 7 8 9 10 11 12 Matrix may contain duplicates.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Siddharth Srivastava -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Sorting:-
I think it can be proved by contradiction that there does not exist a better sorting algorithm than O(mnlogmn) because if there is one then that means we can sort an array better than O(nlgn) by assuming an array as 2D array of k rows and Ceiling(n/k) columns. and if the elements belongs to some range then it may be useful to use Counting or Radix sort depending upon the range On Sat, Sep 24, 2011 at 11:24 PM, siddharth srivastava akssps...@gmail.comwrote: Is the range of numbers provided ? On 24 September 2011 10:26, teja bala pawanjalsa.t...@gmail.com wrote: What is the efficient way to sort a M*N matrix. eg: Given a 3*4 matrix 2 6 7 12 11 8 5 1 9 3 4 10 The ouput should be 1 2 3 4 5 6 7 8 9 10 11 12 Matrix may contain duplicates.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Siddharth Srivastava -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. V 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.
Re: [algogeeks] Re: sqrt function...
let x be the number initialize ans to some value like x or x/2 now repeatedly do the following ans = (ans + x/ans)/2 each time you perform this operation you will move closer to the sqrt value and depending upon the precision required stop On Sat, Sep 24, 2011 at 11:17 PM, siddharth srivastava akssps...@gmail.comwrote: On 24 September 2011 13:45, shady sinv...@gmail.com wrote: one of the simplest way is to do binary search... :) +1 On Sat, Sep 24, 2011 at 8:42 PM, teja bala pawanjalsa.t...@gmail.comwrote: http://www.geeksforgeeks.org/archives/3187 check dis one. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Siddharth Srivastava -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. V 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.
[algogeeks] Re: BST in file
if this is simple BST then only preorder will suffice On Sep 24, 10:16 pm, wetheart gumnaamsm...@yahoo.com wrote: You can put the array representation of binary tree directly, with some obvious modifications ofcourse :) On Sep 24, 5:38 pm, asdqwe ayushgoel...@gmail.com wrote: you can put two traversals of three (inorder, preorder or postorder) in the file.. Two traversals are enough to dedicate a particular tree. On Sep 24, 4:05 pm, Asit Dhal lipu...@gmail.com wrote: I need to print a binary search tree in file. When I will retrieve the same tree from the file. I have thought about printing in xml format like this 100 / \ 50 150 / \ / \ 30 70 120 200 Level 0 100 Level 1 50 Level 2 30 /Level2 Level 2 70 /Level 2 /Level 1 Level 1 150 Level 2 120 /Level 2 Level 2 200 /level 2 /level 1 /level 0 I don't know will this be the best solution or not. Please suggest me how to approach it or some better solution. Regards Asithttp://kodeyard.blogspot.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.
[algogeeks] Re: can any body explain the output and the general method
97!! in whatever sequene rule, it can not print 97. probably you want to say 27 :)) On Sep 23, 4:59 pm, Kunal Yadav kunalyada...@gmail.com wrote: +1 dave Its giving 97 in my compiler. On Fri, Sep 23, 2011 at 4:22 PM, vishwa vishwavam...@gmail.com wrote: its 21 . On Fri, Sep 23, 2011 at 4:10 PM, vijay singh vijaysinghb...@gmail.comwrote: Think it as following... (++i + ++i) + ++i; i.e. (7 + 7) + 8; 1) calculate ++i i.e i=6 2) calculate ++i i.e i=7 3) calculate (i + i) i.e (7+7) = 14 because i is now 7 4) calculate ++i i.e i=8 5) calculate 14 + i i.e 22 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Kunal Yadav (http:/sourcebit.in/ http://algoritmus.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.
[algogeeks] Re : Non Decreasing Numbers
A number is said to be made up of non-decreasing digits if all the digits to the left of any digit is less than or equal to that digit. for eg. 1122, 234, 2 , 0011 is a possible 4 digit non decreasing number so given a number n, how many n digit numbers exist ? for 2 answer = 55 Can someone post complexity and their approach -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Qualcomm
Hello yar, Please share the written paper format and interview questions. If dont want to display openly, plz share with my id mohitm.1...@gmail.com. It will be of great help to me. -- 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/-/GYJ2rAKzQE4J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: EMC^2
since the company is about data and storage manageemnt so do we need to stress on DBMS .?? and thnks fr all the help :) On Sat, Sep 24, 2011 at 11:11 PM, siva viknesh sivavikne...@gmail.comwrote: Total Rounds: max 3. 1 written + 1 tech + 1 hr Probably there might be a 2nd tech interview in case they are willing to take you for the company and want to give you another chance to prove yourself. Tomorrow itself they'll complete the recruitment process and shortlist the candidates. Round 1: Written Test: mostly only general aptitude questions. since the offer is increased, they might ask technical questions. in technical test: mostly C, C++ ( 5 percent chance). and java very very rare.. Based on the number of students short listed after the first round, they would recruit only 1/3rd of the count. Round 2: Technical. There will be three or more types of panels depending on the number of people to be recruited. The panel that you might be called for is purely random and based on the L U C K factor. One panel might have pure coding where in full C and Data Structure questions will be asked. Another panel might ask general theoretical questions from all areas - networks, dbms, oops, c, data structures, etc... even puzzles. The other panel would ask questions only from the area of interest that you specify. Please put in the area which you are strongest at. All possible questions will be asked from your area of interest. HR Round: General as usual questions only. Mostly if you clear the technical rounds, then HR is chumma... namesake. U will be recruited :) :) Some details about the company: Basically a storage management company Core work: RAID groups, storage solutions for other clients. Also working on virtualization (virtual servers) and now moving towards cloud computing ALL THE BEST :) :) On Sep 24, 6:46 pm, aditya kumar aditya.kumar130...@gmail.com wrote: does any one have the idea about emc2 .?? if yes plz do share the details -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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++ Doubts !!
Dude google C++ Faqs. You will find all your answers. You can also buy some books 1. C++ Common Knowledge: Essential Intermediate Programming 2. Effective and More effective C++ 3. C++ gotchas On Sat, Sep 24, 2011 at 11:52 AM, Decipher ankurseth...@gmail.com wrote: Q1) What does the compiler does if I declare a base class VIRTUAL ?? Q2) In the below test code , class A : public B, public C { }; The order of constructor invocation is : B C A but if C is virtual base class the it changes to : C B A Why ?? Q3) Write a macro that swaps any data given to it (Eg: char , int , pointer of any kind , float ) -- 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/-/mj25b-AYRgAJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 online test
25*16*9 / 3! or 5C3 * 5 *4 *3 = 600 On Sat, Sep 24, 2011 at 6:21 PM, Ankur Garg ankurga...@gmail.com wrote: Deoki nandan In MCQ there were options as well ?? is it ? Also were questions in MCQ only from coding or OOPS,DBMS,OS etc also are part of those ? Regards On Sat, Sep 24, 2011 at 6:13 PM, Aamir Khan ak4u2...@gmail.com wrote: @shiv : Correct Answer should be : 5C3 X 5 X 4 X3 = 600 Aamir Khan | 3rd Year | Computer Science Engineering | IIT 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. -- Dipit Grover B.Tech in CSE IIT 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.
[algogeeks] c doubt show me how smart u guys are
i have a file 'star.txt' containing recordss in the form name score as given below *name score* dave 52.67 steve60.09 and so on till 64 names i have to make a program to read and sort these names in a rank just show not to store all scores are in float and need to rank these names in a orderconsider these all students and teacher need a program to rank their percentage in an order to announce ranks lets see some algogeek magic what i did was create a static 2D array of 100 elements and store data from file in it using file handling(obvious) and then use a simple for loop ranking on 2nd line of array please need help guys -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 online test
MCQ had options correct have +1 mark and incorrect had -0.25 marks . MCQ questions were from OS(avg)) ,apti(major) , Networking(avg), Unix(avg), DBMS(minor),coding(major).. On 25 September 2011 02:52, dipit grover digo.d.b...@gmail.com wrote: 25*16*9 / 3! or 5C3 * 5 *4 *3 = 600 On Sat, Sep 24, 2011 at 6:21 PM, Ankur Garg ankurga...@gmail.com wrote: Deoki nandan In MCQ there were options as well ?? is it ? Also were questions in MCQ only from coding or OOPS,DBMS,OS etc also are part of those ? Regards On Sat, Sep 24, 2011 at 6:13 PM, Aamir Khan ak4u2...@gmail.com wrote: @shiv : Correct Answer should be : 5C3 X 5 X 4 X3 = 600 Aamir Khan | 3rd Year | Computer Science Engineering | IIT 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. -- Dipit Grover B.Tech in CSE IIT 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. -- **With Regards Deoki Nandan Vishwakarma * * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse the string word by word . Can someone tell what is wrong in my code ?
//Reverse String word by word // if string is :- I am a good boy //output string should be :- boy good a am I #includestdio.h #includestring.h void reverse(char *p,char*q) { int i;char c; while(pq) { c=*p;*p=*q;*q=c; p++; q--; } } void reverseWordByWord(char str[],int len) { int i=0,j=0; while(ilen) { if((str[i]==' ')||(str[i]=='\t')||(str[i]='\0')) { reverse(str[j],str[i-1]); j=i+1; } i++; } } int main() { char A[]=Ram is a good person; int i; int len=strlen(A); reverse(A[0],A[len-1]); printf(%s\n,A); reverseWordByWord(A,len); printf(%s\n,A); return 0; } -- **With Regards Deoki Nandan Vishwakarma * * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Amazon OS question
A parallel program consists of 8 tasks – T1 through T8. Each task requires one time step to be executed on a single processor. Let X - Y denote the fact that task X must be executed before task Y is executed. Suppose only the tasks X, Y are to be executed. On any multiprocessor machine it would require at least 2 time steps since in the first step X could be executed, and Y could be executed in the next time step (since it requires X to complete first). Now, suppose the following dependencies exist between the tasks T1 – T8: T1 - T2 T2 - T3 T3 - T6 T2 - T4 T4 - T7 T2 - T5 T5 - T8 What is the minimum number of time steps required to execute these 8 tasks on a 2 processor machine and a 4 processor machine? a)4 2 b)5 2 c)5 4 d)6 2 -- Regards, $iva -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] os ques about paging
Consider a virtual memory system in which the virtual page addresses are mapped onto physical page addresses as follow Virtual page address.. Physical page address 03 12 2...1 The address of any byte in this system is given by the ordered pair (v,d) where v = virtual page address d = byte offset in the page Assuming that the main memory is capable of holding 4 page frames, what is the physical address of a byte having the virtual address (0,512) given that the page size is 1024 bytes? a) 3584 b) 2560 c) 1536 d) 512 e) 1024 -- Regards, $iva -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] os ques about paging
3584 On Sun, Sep 25, 2011 at 9:53 AM, sivaviknesh s sivavikne...@gmail.comwrote: Consider a virtual memory system in which the virtual page addresses are mapped onto physical page addresses as follow Virtual page address.. Physical page address 03 12 2...1 The address of any byte in this system is given by the ordered pair (v,d) where v = virtual page address d = byte offset in the page Assuming that the main memory is capable of holding 4 page frames, what is the physical address of a byte having the virtual address (0,512) given that the page size is 1024 bytes? a) 3584 b) 2560 c) 1536 d) 512 e) 1024 -- Regards, $iva -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- ~VISHNU~ -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] os ques about paging
c) 512 On Sun, Sep 25, 2011 at 9:53 AM, sivaviknesh s sivavikne...@gmail.comwrote: Consider a virtual memory system in which the virtual page addresses are mapped onto physical page addresses as follow Virtual page address.. Physical page address 03 12 2...1 The address of any byte in this system is given by the ordered pair (v,d) where v = virtual page address d = byte offset in the page Assuming that the main memory is capable of holding 4 page frames, what is the physical address of a byte having the virtual address (0,512) given that the page size is 1024 bytes? a) 3584 b) 2560 c) 1536 d) 512 e) 1024 -- Regards, $iva -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: sqrt function...
binary search!!! :) On Sat, Sep 24, 2011 at 11:38 PM, sunny agrawal sunny816.i...@gmail.comwrote: let x be the number initialize ans to some value like x or x/2 now repeatedly do the following ans = (ans + x/ans)/2 each time you perform this operation you will move closer to the sqrt value and depending upon the precision required stop On Sat, Sep 24, 2011 at 11:17 PM, siddharth srivastava akssps...@gmail.com wrote: On 24 September 2011 13:45, shady sinv...@gmail.com wrote: one of the simplest way is to do binary search... :) +1 On Sat, Sep 24, 2011 at 8:42 PM, teja bala pawanjalsa.t...@gmail.comwrote: http://www.geeksforgeeks.org/archives/3187 check dis one. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Siddharth Srivastava -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. V 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] os ques about paging
m sry i dint read the question properly page no = vitual page % 3 ie 0 % 3 = 3 thrfre 3*1024 is starting addr of physical page but the byte address will be 3*1024 + 512 = 3584 On Sun, Sep 25, 2011 at 10:12 AM, Vishnu Ganth crazyvishnu...@gmail.comwrote: 3584 On Sun, Sep 25, 2011 at 9:53 AM, sivaviknesh s sivavikne...@gmail.comwrote: Consider a virtual memory system in which the virtual page addresses are mapped onto physical page addresses as follow Virtual page address.. Physical page address 03 12 2...1 The address of any byte in this system is given by the ordered pair (v,d) where v = virtual page address d = byte offset in the page Assuming that the main memory is capable of holding 4 page frames, what is the physical address of a byte having the virtual address (0,512) given that the page size is 1024 bytes? a) 3584 b) 2560 c) 1536 d) 512 e) 1024 -- Regards, $iva -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- ~VISHNU~ -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 OS question
5 4? On Sun, Sep 25, 2011 at 9:33 AM, sivaviknesh s sivavikne...@gmail.comwrote: A parallel program consists of 8 tasks – T1 through T8. Each task requires one time step to be executed on a single processor. Let X - Y denote the fact that task X must be executed before task Y is executed. Suppose only the tasks X, Y are to be executed. On any multiprocessor machine it would require at least 2 time steps since in the first step X could be executed, and Y could be executed in the next time step (since it requires X to complete first). Now, suppose the following dependencies exist between the tasks T1 – T8: T1 - T2 T2 - T3 T3 - T6 T2 - T4 T4 - T7 T2 - T5 T5 - T8 What is the minimum number of time steps required to execute these 8 tasks on a 2 processor machine and a 4 processor machine? a)4 2 b)5 2 c)5 4 d)6 2 -- Regards, $iva -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reverse the string word by word . Can someone tell what is wrong in my code ?
u shud do TWO things in..your reverseword function.. first is str[i]=='\0' and not str[i]='\0' second is while(i=len) and not while(ilen) On Sun, Sep 25, 2011 at 6:49 AM, Deoki Nandan deok...@gmail.com wrote: //Reverse String word by word // if string is :- I am a good boy //output string should be :- boy good a am I #includestdio.h #includestring.h void reverse(char *p,char*q) { int i;char c; while(pq) { c=*p;*p=*q;*q=c; p++; q--; } } void reverseWordByWord(char str[],int len) { int i=0,j=0; while(ilen) { if((str[i]==' ')||(str[i]=='\t')||(str[i]='\0')) { reverse(str[j],str[i-1]); j=i+1; } i++; } } int main() { char A[]=Ram is a good person; int i; int len=strlen(A); reverse(A[0],A[len-1]); printf(%s\n,A); reverseWordByWord(A,len); printf(%s\n,A); return 0; } -- **With Regards Deoki Nandan Vishwakarma * * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Source Bits
which all colleges have sourcebits visited? please share the questions asked/ pattern... thanks -- 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.
Re: [algogeeks] Source Bits
SourceBits visited *RV College of Engineering *in Bangalore on 23rd Sepetember. There were 20 aptitude questions and 10 basic C Questions. 1 Technical interview Round and 1 HR Round. Apti Questions were usually from RS aggarwal (OK Type) C Questions were very easy . Just brush up the basics . In Technical Interviews they asked some basic OOPS concepts,C concepts and on Semaphores and stuff.Quite easy to crack. HR was on Skype where usual HR questions were asked. On Sun, Sep 25, 2011 at 10:55 AM, aanchal goyal goyal.aanch...@gmail.comwrote: which all colleges have sourcebits visited? please share the questions asked/ pattern... thanks -- 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. -- Regards Rajeev N B http://www.opensourcemania.co.cc *Winners Don't do Different things , they do things Differently* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 : Non Decreasing Numbers
can u plz be more..clear ..with wat the input will consist of.. wat does this mean for 2 answer=55 does that mean..that how many non decreasing digits can be formed by 2 digit num On Sun, Sep 25, 2011 at 1:08 AM, shady sinv...@gmail.com wrote: A number is said to be made up of non-decreasing digits if all the digits to the left of any digit is less than or equal to that digit. for eg. 1122, 234, 2 , 0011 is a possible 4 digit non decreasing number so given a number n, how many n digit numbers exist ? for 2 answer = 55 Can someone post complexity and their approach -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Source Bits
thanks a lot rajeev :) On Sun, Sep 25, 2011 at 11:03 AM, rajeev bharshetty rajeevr...@gmail.comwrote: SourceBits visited *RV College of Engineering *in Bangalore on 23rd Sepetember. There were 20 aptitude questions and 10 basic C Questions. 1 Technical interview Round and 1 HR Round. Apti Questions were usually from RS aggarwal (OK Type) C Questions were very easy . Just brush up the basics . In Technical Interviews they asked some basic OOPS concepts,C concepts and on Semaphores and stuff.Quite easy to crack. HR was on Skype where usual HR questions were asked. On Sun, Sep 25, 2011 at 10:55 AM, aanchal goyal goyal.aanch...@gmail.comwrote: which all colleges have sourcebits visited? please share the questions asked/ pattern... thanks -- 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. -- Regards Rajeev N B http://www.opensourcemania.co.cc *Winners Don't do Different things , they do things Differently* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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,* 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.