Re: [algogeeks] interview quest..
yeh. Agree with ramkumar. Simplest solution is to use Stack... On Sun, Feb 6, 2011 at 8:11 PM, Abhijit K Rao wrote: > I could not get it for recursively, but iteratively, I coded a solution. If > anyone knows recursively, > let us know please. > > #include > void main() > { > char s[18]="DGGDBCBHH"; > int i=0,j=0; > int count; > while(s[i]!='\0') > { > if(s[i] == s[i+1]) > { > count = strlen(s)-2; > while(count--) > { >s[i]=s[i + 2]; >i++; > } > s[i]='\0'; > i=0; > } > else > { > i++; > } > } > printf("%s",s); > getch(); > } > > > I/P: DGGDBCBHH O/P: BCB > > Best Regards > Abhijit > > > > On Sun, Feb 6, 2011 at 1:47 PM, ramkumar santhanam < > ramkumars@gmail.com> wrote: > >> use stack. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Google questions
Yeh you are right I Missed something ... nt SuccessorOfANodeInBST(Node N, int givenNumber) { if(N->rightChild != NULL) { N = N->rigthChild; while(N->leftChild != NULL) N = N->leftChild; return (int) N->data; } int iNumberFound = 0; Node K = ParentOf(N); Node J = ParentOf(K); while(1) { if(K == J->leftChild) { iNumberFound = (int) J->data; break; } K = J; J = ParentOf(K); } return iNumberFound; } Now it seems ok to me ...I m ignoring givenNumber parameter...Instead Assuming that Node whose successor we need to find is given as N. Rajan. On Thu, Dec 9, 2010 at 2:05 PM, Shuaib wrote: > > On 09-Dec-2010, at 1:28 PM, rajan goswami wrote: > > 1. > Below is a solution of first problem - > > int SuccessorOfANodeInBST(Node N, int givenNumber) > { > if(N->rightChild != NULL) >return (int) N->rightchild->data; > > > Why this? The right child might not be the next immediate higher number > after givenNumber in the tree. > > > >int iNumberFound = 0; >Node K = ParentOf(N); >Node J = ParentOf(K); > >while(1) >{ > if(K == J->leftChild) > { >iNumberFound = (int) J->data; >break; > } > K = J; > J = ParentOf(K); >} >return iNumberFound; > } > > Rajan. > > On Thu, Dec 9, 2010 at 1:25 PM, Anand wrote: > >> You are given a binary tree. and You need to design a function which takes >> any node from the binary search tree and a number. >> >> Function should be able to return next higher number in binary search tree >> from the given node of binary search tree. >> >> Next higher number means : You given a number. you need to find next >> higher number of that number in a binary search tree if it exist. >> >> I hope this makes it clear. >> >> >> >> >> On Wed, Dec 8, 2010 at 11:27 PM, sahil gujral wrote: >> >>> explain the 1st one again >>> >>> >>> On Thu, Dec 9, 2010 at 11:16 AM, Anand wrote: >>> >>>> One of my friend recently had a telephonic interview and he got two >>>> question to program. >>>> >>>> 1. Given a binary search tree. Write a function which takes any given >>>> node from the binary tree and a number. >>>> Functin has to return the next highest number of the given number >>>> from the binary search tree. >>>> >>>> 2. You have given a structure which has two member, One which stores the >>>> time and other stores the function pointer >>>> Your function has to call the function stored in the fuction poitner >>>> after the time given in the structure elapses. >>>> Design that function? >>>> >>>> >>>> let me know in case if the questions are not clear in any way. >>>> >>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Algorithm Geeks" group. >>>> To post to this group, send email to algoge...@googlegroups.com. >>>> To unsubscribe from 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 algoge...@googlegroups.com. >>> To unsubscribe from 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 algoge...@googlegroups.com. >> To unsubscribe from 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 algoge...@googlegroups.com. &
Re: [algogeeks] Google questions
1. Below is a solution of first problem - int SuccessorOfANodeInBST(Node N, int givenNumber) { if(N->rightChild != NULL) return (int) N->rightchild->data; int iNumberFound = 0; Node K = ParentOf(N); Node J = ParentOf(K); while(1) { if(K == J->leftChild) { iNumberFound = (int) J->data; break; } K = J; J = ParentOf(K); } return iNumberFound; } Rajan. On Thu, Dec 9, 2010 at 1:25 PM, Anand wrote: > You are given a binary tree. and You need to design a function which takes > any node from the binary search tree and a number. > > Function should be able to return next higher number in binary search tree > from the given node of binary search tree. > > Next higher number means : You given a number. you need to find next higher > number of that number in a binary search tree if it exist. > > I hope this makes it clear. > > > > > On Wed, Dec 8, 2010 at 11:27 PM, sahil gujral wrote: > >> explain the 1st one again >> >> >> On Thu, Dec 9, 2010 at 11:16 AM, Anand wrote: >> >>> One of my friend recently had a telephonic interview and he got two >>> question to program. >>> >>> 1. Given a binary search tree. Write a function which takes any given >>> node from the binary tree and a number. >>> Functin has to return the next highest number of the given number >>> from the binary search tree. >>> >>> 2. You have given a structure which has two member, One which stores the >>> time and other stores the function pointer >>> Your function has to call the function stored in the fuction poitner >>> after the time given in the structure elapses. >>> Design that function? >>> >>> >>> let me know in case if the questions are not clear in any way. >>> >>> >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to algoge...@googlegroups.com. >>> To unsubscribe from 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 algoge...@googlegroups.com. >> To unsubscribe from 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 algoge...@googlegroups.com. > To unsubscribe from 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 algoge...@googlegroups.com. To unsubscribe from 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: convert binary matrix to zero matrix
@Prims Can you please elaborate the problem in detail... What do you mean by toggling row and column... 1 Interchanging a row with some column ? 2 Changing 0s to 1s and 1s to 0s of that row ? or Some thing else ? In both options mentioned above .. no of 1s present in a matrix can not be changed to 0s in any ways ... Please explain the step that can be performed on given matrix. regards, Rajan. On Mon, Dec 6, 2010 at 11:55 PM, Prims wrote: > Amir > > Could you please explain with an example in detail? > > > > On Dec 6, 7:02 pm, Amir hossein Shahriari > wrote: > > actually a greedy approach for this problem exists: > > just convert the first row and first column to all zeros > > if after this step matrix is not a complete zero matrix then it's > impossible > > to make it > > > > > > > > On Sun, Dec 5, 2010 at 9:10 AM, Prims wrote: > > > How do i convert a binary matrix(containing only 0s and 1s) to a > > > complete zero matrix? Only operations allowed are u can toggle a whole > > > row or a whole column. The conversion has to be done in minimum number > > > of steps (a step is defined as toggling a whole row or whole column > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "Algorithm Geeks" group. > > > To post to this group, send email to algoge...@googlegroups.com. > > > To unsubscribe from this group, send email to > > > algogeeks+unsubscr...@googlegroups.com > > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text - > > > > - Show quoted text - > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from 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 algoge...@googlegroups.com. To unsubscribe from 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: Adobe question
@Dave - There could be another good solution instead of XOR. If below interpretation of the problem is correct, Array1 -> contains n elements ( order is irrelevent) Array2 -> contains all n elements of Array1 ( order is irrelevent) + 1 extra element which is unique from all n elements of Array1. ==> Then unique element from second array = (Addition of all elements of Array2) - (Addition of all elements of Array1). Rajan. On Thu, Oct 21, 2010 at 8:12 PM, Dave wrote: > I think that you are saying that the second array contains all of the > elements in the first array, plus one additional element. If this is > the proper interpretation, then just XOR all of the elements of both > arrays and the result is the additional element. > > Dave > > On Oct 21, 9:12 am, bittu wrote: > > Given 2 array in first array n elements are sorted there in second > > elements n+1 elements and n elements in 2nd array not ordered and it > > also contains one extra elements wap to find out extra elements in one > > pass. > > > > Regards > > Shashank Mani > > BIT Mesra > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from 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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.