[algogeeks] Re: MS Question: Add two large numbers where the numbers are stored in an array format

2012-06-26 Thread rspr
- in general we use polynomial addition for the same. If the numbers are carrying some additional information as ( particular base or pattern) another mechanise can be designed On Tuesday, 26 June 2012 15:40:39 UTC+5:30, ashgoel wrote: Best Regards Ashish Goel Think positive and find fuel

Re: [algogeeks] Re: MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-18 Thread Abhishek Sharma
In a stack, you can't access any element directly, except the top one. On Mon, Jun 18, 2012 at 11:33 AM, Rituraj worstcod...@gmail.com wrote: My iterative approach /*code in c*/ #includestdio.h int main() { int stack[]={1,2,3,4,5,6,7,8},top=7;// int i,j,temp; for(i=1;i=top;i++) {

Re: [algogeeks] Re: MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-18 Thread aditya gupta
this is not a stack at all, u have just named it as a stack. for it to be a stack u should access only the top most element at any point of time!!! On Mon, Jun 18, 2012 at 11:33 AM, Rituraj worstcod...@gmail.com wrote: My iterative approach /*code in c*/ #includestdio.h int main() { int

Re: [algogeeks] Re: MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-18 Thread Prem Nagarajan
I think there is a problem in this solution. U r accessing stack elements from 1 to n in the outer loop. It is not possible. 1st element cannot be accessed without popping first n-1 elements out. On Mon, Jun 18, 2012 at 11:33 AM, Rituraj worstcod...@gmail.com wrote: My iterative approach

Re: [algogeeks] Re: MS Question : find word in 2D array

2012-06-12 Thread hary rathor
1 search should in using KMP algo so that It can be seacrh in O(n) . let function is int KMP(src,trget, searchDirection ) this kmpSearch funtion should be implemented is such a fashion that is search in both direction. 3. assume that give 2d array name is array const int row =1; const int col

[algogeeks] Re: MS Question : find word in 2D array

2012-06-10 Thread Arman Kamal
This can be done with a dfs to mark the path and a backtrack to construct the path or the word itself. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this

Re: [algogeeks] Re: MS question : string compression

2012-06-08 Thread Ashish Goel
#include stdafx.h #include iostream using namespace std; const int len = 20; const int maxCount = 127; int rle(char* pStr, int length, char* pNew) { if (!pStr) return -1; if (length 3) return -1; int i = 0; int k = 0; char p1 = pStr[i++]; char p2 = pStr[i++]; char p3 = pStr[i++]; int pos=0;

Re: [algogeeks] Re: MS question : string compression

2012-06-08 Thread Ashish Goel
Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jun 8, 2012 at 12:54 PM, Ashish Goel ashg...@gmail.com wrote: #include stdafx.h #include iostream using namespace std; const int len = 20; const int maxCount = 127; int rle(char* pStr,

Re: [algogeeks] Re: MS question : string compression

2012-06-07 Thread Ashish Goel
The idea here is that there will be parts of the stream which actually should not be compressed. For example abcdef as well as aa do not need any compression. We need to compress only if 3 characters match because for compressing two chars we will take up 2 chars so no compression benefit (: So

Re: [algogeeks] Re: MS question : string compression

2012-05-27 Thread Ashish Goel
Will fail for the sing having say 257characters all same Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Sat, May 26, 2012 at 12:26 PM, Navin Gupta navin.nit...@gmail.comwrote: This is called Run-Length-Encoding (RLE) of a string. Its purpose

Re: [algogeeks] Re: MS question : string compression

2012-05-26 Thread Hassan Monfared
u forgot to do inplace and you have wrong conversion of count On Sat, May 26, 2012 at 11:31 AM, Anchal Gupta anchal92gu...@gmail.comwrote: hey, here is the function that do the compression and store the output in an array op. void str_comp(char *str) { int count=0,j=0,i; char

[algogeeks] Re: MS question : string compression

2012-05-26 Thread Anchal Gupta
yeah i forgot inplace so to do that we simply add count and ch in str input array instead of op. btw whats wrong with count it give me right answer. On May 26, 12:08 pm, Hassan Monfared hmonfa...@gmail.com wrote: u forgot to do inplace and you have wrong conversion of count On Sat, May 26,

Re: [algogeeks] Re: MS question : string compression

2012-05-26 Thread Hassan Monfared
1- try abb On Sat, May 26, 2012 at 12:07 PM, Anchal Gupta anchal92gu...@gmail.comwrote: yeah i forgot inplace so to do that we simply add count and ch in str input array instead of op. btw whats wrong with count it give me right answer. On May 26, 12:08 pm,

Re: [algogeeks] Re: MS question : string compression

2012-05-26 Thread Ashish Goel
http://michael.dipperstein.com/rle/index.html and basic one is http://www.fileformat.info/mirror/egff/ch09_03.htm Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Sat, May 26, 2012 at 1:10 PM, Hassan Monfared hmonfa...@gmail.comwrote: 1- try

[algogeeks] Re: MS question : string compression

2012-05-26 Thread Navin Gupta
This is called Run-Length-Encoding (RLE) of a string. Its purpose is to save space.So in case of abcdef,I think the output needed is abcdef (1 is implicit). The added benefit is it makes the solution in-place. Approach:- (In-place and Linear Time) Start from the left of string and

Re: [algogeeks] Re: MS Question -Reverse a Linked List in size of 2

2012-01-24 Thread Ashish Goel
struct node { int data; struct node *link; }; node* CreateNode(int val) { node* root = (node*)malloc(sizeof(struct node)); root-data = val; root-link = NULL; return root; } node* createList(int *arr, int n) { node * root =

Re: [algogeeks] Re: MS Question -Reverse a Linked List in size of 2

2012-01-24 Thread atul anand
@Ashish : seems exactly similar to Lucifer code or you modified something in his code ?? ... On Tue, Jan 24, 2012 at 2:02 PM, Ashish Goel ashg...@gmail.com wrote: struct node { int data; struct node *link; }; node* CreateNode(int val) { node* root =

Re: [algogeeks] Re: MS Question -Reverse a Linked List in size of 2

2012-01-24 Thread Ashish Goel
oh, a possible mistake from my side, ignore my mail please... Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Tue, Jan 24, 2012 at 3:08 PM, atul anand atul.87fri...@gmail.com wrote: @Ashish : seems exactly similar to Lucifer code or you

Re: [algogeeks] Re: MS Question -Reverse a Linked List in size of 2

2012-01-24 Thread praveen raj
Steps: 1)Reverse the list ... 2)Now do the swap two nodes... consecutively... PRAVEEN RAJ DELHI COLLEGE OF ENGINEERING -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To

[algogeeks] Re: MS Question -Reverse a Linked List in size of 2

2012-01-23 Thread Lucifer
I just wrote a code which would work for any given size K. I tested it with K = 1 till 7. [ in the question asked above K=2] Also, tested for corner cases.. If you guys are interested, then have a look at the code.. I have added few helper functions so that you can directly run the code and use

[algogeeks] Re: MS Question -Reverse a Linked List in size of 2

2012-01-23 Thread Lucifer
@above attaching the file.. -- 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/-/YW_phbT3me4J. To post to this group, send email to algogeeks@googlegroups.com.

[algogeeks] Re: MS question

2011-10-03 Thread pranav agrawal
@rahul sharma, i ran this code, it is producing wrong answer :| check it, http://codepad.org/THv1hJq1 anyone with correct solution? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit

Re: [algogeeks] Re: MS question

2011-10-03 Thread shady
search archives :-/ On Mon, Oct 3, 2011 at 11:47 AM, pranav agrawal pranav.is.cool.agra...@gmail.com wrote: @rahul sharma, i ran this code, it is producing wrong answer :| check it, http://codepad.org/THv1hJq1 anyone with correct solution? -- You received this message because you are

Re: [algogeeks] Re: MS question

2011-10-03 Thread rahul sharma
yeah it is wrong..i have a solution but uses 0(n+m) space.i need it in 0(n*m) tymand o(1) space On Mon, Oct 3, 2011 at 11:55 AM, shady sinv...@gmail.com wrote: search archives :-/ On Mon, Oct 3, 2011 at 11:47 AM, pranav agrawal pranav.is.cool.agra...@gmail.com wrote: @rahul

Re: [algogeeks] Re: MS question

2011-10-03 Thread Ashish Goel
keep two var row0 and col0 for checking if there is any 0 in row0flag /col0flag now walk over elements from 1,1 to n,m and set corresponding entry in 0th row /column if you hit a zero. now walk over zeroth column and rwo and set the complete row/col if a 0 is there in 0th row/col. after this

Re: [algogeeks] Re: MS question

2011-10-03 Thread rahul sharma
@ashish can u give an xample.plz...i have read a lot archives ...but cant find in 0(1) spaceu using 2 var only...plz give xample...nended urgent.thnx On Tue, Oct 4, 2011 at 7:26 AM, Ashish Goel ashg...@gmail.com wrote: keep two var row0 and col0 for checking if there is any 0 in

Re: [algogeeks] Re: MS question

2011-10-03 Thread Ashish Goel
1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 0 row0 is true col0 is true for (int i=1; in;i++) for (int j=1;jm;j++) if (a[i][j] == 0) {a[i][0]=0; a[0][j]=0;} now after this 1 1 0 0 0 1 1 1 1 1 1 1 0 1 1 0 for (int i=1; in;i++) if (a[i][0] ==0) for (int j=1; jm;j++) a[i][j]=0; for (int j=1; im;j++) if

Re: [algogeeks] Re: MS question

2011-10-03 Thread rahul sharma
row0 and col0 initilayy true coz we have 0 in 0 row???or these r default values? On Tue, Oct 4, 2011 at 8:07 AM, Ashish Goel ashg...@gmail.com wrote: 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 0 row0 is true col0 is true for (int i=1; in;i++) for (int j=1;jm;j++) if (a[i][j] == 0) {a[i][0]=0;

Re: [algogeeks] Re: MS question

2011-10-03 Thread Ashish Goel
0 in 0th row as well as 0 in 0th col and hence true Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Tue, Oct 4, 2011 at 8:28 AM, rahul sharma rahul23111...@gmail.comwrote: row0 and col0 initilayy true coz we have 0 in 0 row???or these r default

Re: [algogeeks] Re: MS question

2011-10-03 Thread rahul sharma
so we shoul d aslo add loop at the top to find only for firrst row and column the initial values On Tue, Oct 4, 2011 at 8:30 AM, Ashish Goel ashg...@gmail.com wrote: 0 in 0th row as well as 0 in 0th col and hence true Best Regards Ashish Goel Think positive and find fuel in failure

Re: [algogeeks] Re: MS question

2011-10-03 Thread rahul sharma
got it..thnx yr On Tue, Oct 4, 2011 at 8:34 AM, rahul sharma rahul23111...@gmail.comwrote: so we shoul d aslo add loop at the top to find only for firrst row and column the initial values On Tue, Oct 4, 2011 at 8:30 AM, Ashish Goel ashg...@gmail.com wrote: 0 in 0th row as well as 0 in 0th

Re: [algogeeks] Re: MS Question - Median of a BST without using extra space and in O(n)

2011-09-28 Thread anshu mishra
*@all to median of BST time O(n) space O(1) (modified code of nitin to get median) medianBST*(node, n) int x = 0; *while* hasleftchild(node) *do* node = node.left *do* x++; if (x == n/2) return node-val; *if* (hasrightchild(node)) *then* node = node.right

[algogeeks] Re: MS question

2011-09-27 Thread Gene
If you're given that it's a sparse matrix, then you must assume storage is in a sparse matrix data structure to get time less than O(mn). In fact, if you assume the right data structure, then the operation can take O(1) time. For example if you say the structure is an array of sets of indices of

Re: [algogeeks] Re: MS question

2011-09-27 Thread Yogesh Yadav
Suppose matrix is 1 0 0 1 1 0 1 0 0 0 0 0 then we traverse the matrix for each 1 we found at a[i][j] , we will check for i=i to irow and j=j to jcol if that contains any more 1 if it contains 1 in row then we don't make the whole row as 1..we ignore the row and same will be for column

[algogeeks] Re: MS Question - Median of a BST without using extra space and in O(n)

2011-09-27 Thread Gene
And you have to use the pointer-reversing trick to traverse the tree because you don't have space for a stack. On Sep 27, 4:52 am, anshu mishra anshumishra6...@gmail.com wrote: do the inorder traversal as soon as reached at n/2th element that will be median. -- You received this message

[algogeeks] Re: MS Question - Median of a BST without using extra space and in O(n)

2011-09-27 Thread Gene
This requires O(n) extra space. On Sep 27, 7:43 am, anshu mishra anshumishra6...@gmail.com wrote: int bstMedian(node *root, int n, int x) {     if (node-left) return bstMedian(root-left, n, x);     x++;     if (x == n/2) return node-val;     if (node-right) return bstMedian(root-right, n,

Re: [algogeeks] Re: MS Question - Median of a BST without using extra space and in O(n)

2011-09-27 Thread anshu mishra
its not o(n) it is O(max height of tree) :P i have not seen the constraint. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

[algogeeks] Re: MS Question - Median of a BST without using extra space and in O(n)

2011-09-27 Thread vikas
a simple one is rabit-tortoise method, and using stackless traversal, facing a lot of corner cases in coding this, can someone check this as well? On Sep 27, 6:41 pm, anshu mishra anshumishra6...@gmail.com wrote: its not o(n) it is O(max height of tree) :P i have not seen the constraint. --

Re: [algogeeks] Re: MS Question - Median of a BST without using extra space and in O(n)

2011-09-27 Thread Dheeraj Sharma
@anshu can middle element can be found if the no. of nodes are not given... On Tue, Sep 27, 2011 at 8:34 PM, vikas vikas.rastogi2...@gmail.com wrote: a simple one is rabit-tortoise method, and using stackless traversal, facing a lot of corner cases in coding this, can someone check this as

Re: [algogeeks] Re: MS Question - Median of a BST without using extra space and in O(n)

2011-09-27 Thread Sanjay Rajpal
Recursion also requires space, so the problem is how to traverse without extra space. Once this is done, nothing is left in the problem. Sanju :) On Tue, Sep 27, 2011 at 8:35 AM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: @anshu can middle element can be found if the no. of nodes

Re: [algogeeks] Re: MS Question - Median of a BST without using extra space and in O(n)

2011-09-27 Thread Nitin Garg
Do inorder traversal, to find out the total no. of nodes. Next time, do the inorder traversal but keeping the count of nodes visited and stop when you visit n/2 nodes. Non recursive In-order Traversal - *inorder*(node) *while* hasleftchild(node) *do* node = node.left *do*

Re: [algogeeks] Re: MS Question - Median of a BST without using extra space and in O(n)

2011-09-27 Thread Sanjay Rajpal
Since we are given pointer to root node, we can easily find the minimum element in the tree. This will be the first node in the inorder traversal, now use method to find the inorder successor of a each node. Do it iteratively. Complexity will be O(n log n) and O(n) if tree is skewed. Correct me

[algogeeks] Re: MS Question - Median of a BST without using extra space and in O(n)

2011-09-27 Thread geeks
morris Inorder traversal can do the task i think -- 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/-/TujHItNRKowJ. To post to this group, send email to

[algogeeks] Re: MS question

2011-09-26 Thread Gene
I assume we don't want to use extra storage. So one way is this: Go over the matrix and mark the first row with a 1 and the first column with a 1 for each 1 you find. Because row and column 1 are used for temporary storage in this manner, you must first remember whether they contained a 1, then

Re: [algogeeks] Re: MS question

2011-09-26 Thread Ankur Garg
Guys an Update , This has been asked in MS by me.. I suggested O(m*n) but they were looking for a solution in nlogn ( n*n Sparse Matrix ) ..Any idea ... This post was discussed earlier but every1 came with O(m*n) solution so instead of cluttering it ..opened a new One ... On Tue, Sep 27, 2011

[algogeeks] Re: MS Question

2011-08-25 Thread vikas
yep, trie needs to be built On Aug 24, 10:49 pm, Ankur Garg ankurga...@gmail.com wrote: It means when u call that func u get the next word in the document Regards Ankur On Wed, Aug 24, 2011 at 6:59 PM, vikas vikas.rastogi2...@gmail.com wrote: what do you mean by a function for

Re: [algogeeks] Re: MS Question

2011-08-25 Thread SANDEEP CHUGH
wat abt doing wid hashing? On Thu, Aug 25, 2011 at 3:55 PM, vikas vikas.rastogi2...@gmail.com wrote: yep, trie needs to be built On Aug 24, 10:49 pm, Ankur Garg ankurga...@gmail.com wrote: It means when u call that func u get the next word in the document Regards Ankur

Re: [algogeeks] Re: MS Question

2011-08-25 Thread nishaanth
ya why not hashing ? On Thu, Aug 25, 2011 at 3:31 PM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote: wat abt doing wid hashing? On Thu, Aug 25, 2011 at 3:55 PM, vikas vikas.rastogi2...@gmail.comwrote: yep, trie needs to be built On Aug 24, 10:49 pm, Ankur Garg ankurga...@gmail.com wrote:

[algogeeks] Re: MS Question

2011-08-25 Thread Shrey Choudhary
how will we exactly implement hashtables in this? What will be appropriate keys? ?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Re: MS Question

2011-08-25 Thread SANDEEP CHUGH
for every word in the document , apply hash funtion.. store the string n its frequency too.. if we get the same word , then increment the frequency. after storing. whenver we want to search the word , searching in O(1) time , jst applying hash function again on the word to be searched ..

[algogeeks] Re: MS Question

2011-08-25 Thread Shrey Choudhary
But it says finding the next word and also it's position of occurence. If we use frequency..won't position of occurence overlap? Am not sure whether I got the question right or not! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

Re: [algogeeks] Re: MS Question

2011-08-25 Thread SANDEEP CHUGH
no .. question says that there is a function that gives the next word in the document.. this means after hashing one word , we hav to go to another word ... for this going to next word in the document , we hav already provided wid a function.. nothing to do wid the occurence On Thu, Aug 25,

[algogeeks] Re: MS Question

2011-08-25 Thread Shrey Choudhary
design a code which efficiently search the word and find occurrence of it in given document -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group,

Re: [algogeeks] Re: MS Question

2011-08-25 Thread SANDEEP CHUGH
ohh sry my mistake .. got it On Thu, Aug 25, 2011 at 7:36 PM, Shrey Choudhary choudharyshre...@gmail.com wrote: design a code which efficiently search the word and find occurrence of it in given document -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] Re: MS Question

2011-08-25 Thread SANDEEP CHUGH
@shrey but its not given in question that we have to return the position or the occurence in the document.. we hav to only the tell whether the word is in document.. read .design a code which efficiently search the word and find occurrence of it in given document . its nt given that return

Re: [algogeeks] Re: MS Question

2011-08-25 Thread Shrey Choudhary
i made a boo boo -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit

[algogeeks] Re: MS Question

2011-08-24 Thread vikas
what do you mean by a function for finding the next word is given ? On Aug 22, 1:56 am, Ankur Garg ankurga...@gmail.com wrote: Question--      Given a document containing some words ...and a function for finding the next word is given .design a code which efficiently   search the word  

Re: [algogeeks] Re: MS Question

2011-08-24 Thread Ankur Garg
It means when u call that func u get the next word in the document Regards Ankur On Wed, Aug 24, 2011 at 6:59 PM, vikas vikas.rastogi2...@gmail.com wrote: what do you mean by a function for finding the next word is given ? On Aug 22, 1:56 am, Ankur Garg ankurga...@gmail.com wrote:

[algogeeks] Re: MS question

2011-08-09 Thread Priyanshu
Anyone?? Regards, Priyanshu Gupta On Fri, Aug 5, 2011 at 6:09 PM, priyanshu priyanshuro...@gmail.com wrote: Give an efficient algorithm to determine which part of the video should be displayed as a thumbnail?? -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] Re: MS question

2011-08-09 Thread *$*
I guess , it can be done using indexing , with time stamp as key , and frame pointer as data .. Please correct me if I am wrong. On Tue, Aug 9, 2011 at 11:03 PM, Priyanshu priyanshuro...@gmail.com wrote: Anyone?? Regards, Priyanshu Gupta On Fri, Aug 5, 2011 at 6:09 PM, priyanshu

Re: [algogeeks] Re: MS question

2011-08-09 Thread Aditya Virmani
i guess ur qn was how will u decide which frame shud b ur thumbnail...as after tht, the frame cud be set as a thumbnail which is pretty much an eay task in windows programming.i think most, dun hav much info abt it though, thumbnails shud contain more of data; i mean shudnt be unicolour(blank

Re: [algogeeks] Re: MS question

2011-08-09 Thread Priyanshu
@gopi.. didnt got you... @adi.. ya thats what i am talking about... Regards, Priyanshu Gupta On Tue, Aug 9, 2011 at 11:18 AM, Aditya Virmani virmanisadi...@gmail.comwrote: i guess ur qn was how will u decide which frame shud b ur thumbnail...as after tht, the frame cud be set as a

[algogeeks] Re: MS question

2011-08-09 Thread monish001
Given : ddbbccae O/P : 2d4a2b2c1a1e What is happening? What algo? Thanks and regards Monish On Aug 9, 5:59 pm, ankit sambyal ankitsamb...@gmail.com wrote: Given an array of characters, change the array to something as shown in the following example. Given : ddbbccae O/P :

Re: [algogeeks] Re: MS question

2011-08-09 Thread abhijeet srivastva
Below is a solution - #include stdio.h int main(int argc, char* argv[]){ int i = 0; char *array = argv[1]; char prev = array[0]; while(array[i]){ int count = 0; while(prev == array[i]){ i +=1;

Re: [algogeeks] Re: MS question

2011-07-29 Thread vaibhav agarwal
what has palindrome to do with this? On Mon, Jul 18, 2011 at 1:11 AM, swetha rahul swetharahu...@gmail.comwrote: Thanks everyone!! On Sun, Jul 17, 2011 at 10:56 PM, ankit sambyal ankitsamb...@gmail.comwrote: Check for case senstivity also: eg: Madam and madam both are palindromes.

Re: [algogeeks] Re: MS question

2011-07-29 Thread rajeev bharshetty
Test cases for MSN Search Engine 1 : Check for auto completion feature (The auto completion based on the prefix should provide suggestions for the most searched keyword with that prefix) . 2 : The spelling correction feature which shows as to what the user actually meant. This should be highly

[algogeeks] Re: MS question

2011-07-17 Thread Nishant
1.If string is NULL then it should return 1 i.e. string is palindrome 2.If there is only one character in string then it is palindrome 3.If reverse of given string is same as string On Jul 17, 8:18 pm, swetha rahul swetharahu...@gmail.com wrote: ya got it..thanks... how abt test cases for

Re: [algogeeks] Re: MS question

2011-07-17 Thread swetha rahul
is this ans sufficient..? any other possible test cases for palindrome ? On Sun, Jul 17, 2011 at 8:53 PM, Nishant mittal.nishan...@gmail.com wrote: 1.If string is NULL then it should return 1 i.e. string is palindrome 2.If there is only one character in string then it is palindrome 3.If

[algogeeks] Re: MS question

2011-07-17 Thread Dumanshu
Well, for the third case, you can elaborate on the implementation. We need to compare the first half with the later half. So, in case of even no. of characters it splits perfectly and in case of odd number of characters, just ignore the middle character. On Jul 17, 8:28 pm, swetha rahul

Re: [algogeeks] Re: MS question

2011-07-17 Thread vaibhav agarwal
check for query injection,string like (spaces,nothing) entered. On Sun, Jul 17, 2011 at 9:04 PM, Dumanshu duman...@gmail.com wrote: Well, for the third case, you can elaborate on the implementation. We need to compare the first half with the later half. So, in case of even no. of characters

Re: [algogeeks] Re: MS question

2011-07-17 Thread ankit sambyal
Check for case senstivity also: eg: Madam and madam both are palindromes. Also for clarify with the interviewer whether whitespace and punctuation can be ignored. eg: is the following string a palindrome or not: A man, a plan, a canal, Panama And check for this condition accordingly -- You

Re: [algogeeks] Re: MS question

2011-07-17 Thread swetha rahul
Thanks everyone!! On Sun, Jul 17, 2011 at 10:56 PM, ankit sambyal ankitsamb...@gmail.comwrote: Check for case senstivity also: eg: Madam and madam both are palindromes. Also for clarify with the interviewer whether whitespace and punctuation can be ignored. eg: is the following string a

Re: [algogeeks] Re: MS question

2011-06-29 Thread rizwan hudda
@Dave: Think of it again counting sort won't work, If you are just considering the last character as the even though key is just last character, the value is the whole string.. On Tue, Jun 28, 2011 at 1:53 PM, juver++ avpostni...@gmail.com wrote: List[letter] - linked list of all words with

[algogeeks] Re: MS question

2011-06-29 Thread Dave
@Rizwan: I don't see the problem. Initialize an array of counters, one for each possible last character, to zero. If there are no restrictions on the last character, use an array of 256 counters. Then, for each string, increment the counter corresponding to the last character of the string by the

Re: [algogeeks] Re: MS question

2011-06-28 Thread Kamakshii Aggarwal
@Dave:can u please explain the second method. On Mon, Jun 27, 2011 at 11:24 PM, Dave dave_and_da...@juno.com wrote: @Nishant: Here are a couple of O(n) alternatives, given that there are a limited number of last characters and no requirement to break ties in any particular way: 1. A

Re: [algogeeks] Re: MS question

2011-06-28 Thread juver++
List[letter] - linked list of all words with the last character as letter. Then iterate over all letters and concatenate lists. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit

[algogeeks] Re: MS question

2011-06-27 Thread Sanket
Do we really need to reverse? Can't we apply any normal sorting algo like merge sort or quick sort and for the comparison part of it, use the last characters of each string only? On Jun 27, 4:21 am, varun pahwa varunpahwa2...@gmail.com wrote: reverse all strings and then sort. On Mon, Jun 27,

[algogeeks] Re: MS question

2011-06-27 Thread Dave
@Nishant: Here are a couple of O(n) alternatives, given that there are a limited number of last characters and no requirement to break ties in any particular way: 1. A counting sort. 2. Form a linked list of entries corresponding to each last character, and then merge these lists in collating

[algogeeks] Re: MS Question

2011-06-25 Thread Dan
I don't think you need a temp string (though, this may be a language dependent issue). Just use the string as given and keep track of the character positions within the string. The length of the original string is irrelevant as long as your system can handle it. Dan :-) On Jun 23, 2:44 pm,

Re: [algogeeks] Re: MS Question

2011-06-14 Thread Divye Kapoor
Good one! That halved the memory requirement. :) -- 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/-/N6mbMaJHO64J. To post to this group, send email to

[algogeeks] Re: MS Question

2011-06-14 Thread Dumanshu
@Sunny: what if the number is repeated multiple times? u seem to consider only the duplicates(2 times). On Jun 13, 7:36 pm, sunny agrawal sunny816.i...@gmail.com wrote: no we can take care of duplicates without any extra memory modify 2nd step of my previous solution as follows if T[a[i]] is

Re: [algogeeks] Re: MS Question

2011-06-14 Thread Arpit Sood
i meant if N = { 1, 1, 1, 2, 12} and M = { 1, 1, 3, 12} then answer should be = {1, 1, 12} On Mon, Jun 13, 2011 at 8:06 PM, sunny agrawal sunny816.i...@gmail.comwrote: no we can take care of duplicates without any extra memory modify 2nd step of my previous solution as follows if T[a[i]] is

Re: [algogeeks] Re: MS Question

2011-06-14 Thread sunny agrawal
Nice Confusion... :) Consider the following case A[M] = {1,1,3,12}; B[N] = {1,2,12} here again i think answer should be {1,1,12} , why are u binding one occurrence of 1 in array A with one in B. Question is which elements of first array is present in second array. so for this case A[0], A[1],

[algogeeks] Re: MS Question

2011-06-13 Thread Divye Kapoor
Use a hash table of size 1025 with bits per table entry = 2. 1. Go through the N sized array and set bit 0 of the hash table entry to 1 if it is present in the first array. 2. Go through the M sized array and set bit 1 of the hash table entry to 1 if the element belongs to 0 to 1024. 3. Go

Re: [algogeeks] Re: MS Question

2011-06-13 Thread sunny agrawal
why do we need 2 bits at all ?? i think single bit per table entry will do. say table is T[1025], and array is A[M] 1. Go through the N sized array and set bit 0 of the hash table entry to 1 if it is present in the first array. 2. Go through the M sized array and if T[a[i]] is set then this

Re: [algogeeks] Re: MS Question

2011-06-13 Thread Arpit Sood
we can take care of the duplicate entries, but then that would cost more space(int), as of now we are working with bool On Mon, Jun 13, 2011 at 5:51 PM, sunny agrawal sunny816.i...@gmail.comwrote: that will report duplicate entries multiple times :( On Mon, Jun 13, 2011 at 5:38 PM, sunny

Re: [algogeeks] Re: MS Question

2011-06-13 Thread sunny agrawal
no we can take care of duplicates without any extra memory modify 2nd step of my previous solution as follows if T[a[i]] is set then this element is there in second array so report this element and Reset T[a[i]]. now no duplicates will be reported. and only 1025 bits will be required. any

[algogeeks] Re: MS Question :decrement, subtract and dividewith setZero, setEqual, increaseby1 and loop macro

2010-08-24 Thread Gene
You can really impress 'em by pointing out that this problem is related to some common ways of representing numbers and arithmetic operations in the lambda calculus. On Aug 24, 7:16 pm, Ashish Goel ashg...@gmail.com wrote: inline int decrease (int v) { int decreasedVal = 0; int counter = 0;

[algogeeks] A MS QUESTION

2009-12-15 Thread vicky
Given a file with a lot of words (10 million) find out the top 10% most frequently occuring words. -- 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,

Re: [algogeeks] A MS QUESTION

2009-12-15 Thread abhijith reddy
*TRIE*: Using a trie we would get a linear time solution but i think the memory requirement would be huge .. On Mon, Dec 14, 2009 at 11:02 PM, vicky mehta...@gmail.com wrote: Given a file with a lot of words (10 million) find out the top 10% most frequently occuring words. -- You

Re: [algogeeks] A MS QUESTION

2009-12-15 Thread sharad kumar
can u make use of binary index trees On Tue, Dec 15, 2009 at 4:23 PM, abhijith reddy abhijith200...@gmail.comwrote: *TRIE*: Using a trie we would get a linear time solution but i think the memory requirement would be huge .. On Mon, Dec 14, 2009 at 11:02 PM, vicky mehta...@gmail.com

Re: [algogeeks] A MS QUESTION

2009-12-15 Thread Roshan Mathews
On Mon, Dec 14, 2009 at 11:02 PM, vicky mehta...@gmail.com wrote: Given a file with a lot of words (10 million) find out the top 10% most frequently occuring words. http://www.cc.gatech.edu/classes/semantics/misc/pp2.pdf -- You received this message because you are subscribed to the Google