Re: [algogeeks] Re: remove duplicate words in a string

2011-08-05 Thread Nitin Nizhawan
@deepika this is a different question, your solution is great for removing duplicate characters. original question is about removing duplicate words. On Fri, Aug 5, 2011 at 7:06 PM, deepikaanand wrote: > ya an array of 256 is surely a wastage of space but this was i couls > think in my microsoft

[algogeeks] Re: remove duplicate words in a string

2011-08-05 Thread deepikaanand
ya an array of 256 is surely a wastage of space but this was i couls think in my microsoft interview as the result should have also been i place that is i/p : AAA BBB CCC o/p:A BC//space should also be removed ::explanantion s[0] is alwayz unique therfor array[s[0]] = 1 => this char has already occ

Re: [algogeeks] Re: remove duplicate words in a string

2011-08-05 Thread mithun bs
Can you please explain this? Is array[256] not extra space? On Fri, Aug 5, 2011 at 5:14 PM, deepikaanand wrote: > static int array[256]; > removedupli(char s[],int n) > { > array[s[0]]=1; > for(i=1;i { > if(array[s[i]]==0) > array[s[i]]=1; > else > { > for(pos=i;i s[pos]=s[pos+1]; > i--; > } > }

[algogeeks] Re: remove duplicate words in a string

2011-08-05 Thread deepikaanand
static int array[256]; removedupli(char s[],int n) { array[s[0]]=1; for(i=1;ihttp://groups.google.com/group/algogeeks?hl=en.

Re: [algogeeks] Re: remove duplicate words in a string

2011-08-05 Thread vaibhav shukla
these are the final requirements Remove duplicate words, no extra space, On Fri, Aug 5, 2011 at 2:12 PM, Gaurav Menghani wrote: > Vaibhav, please don't dynamically alter the requirements of the > problem :-) Better to say them up front. > > On Fri, Aug 5, 2011 at 2:10 PM, vaibhav shukla > wr

Re: [algogeeks] Re: remove duplicate words in a string

2011-08-05 Thread Gaurav Menghani
Vaibhav, please don't dynamically alter the requirements of the problem :-) Better to say them up front. On Fri, Aug 5, 2011 at 2:10 PM, vaibhav shukla wrote: > provide a solution whether greater than O(n) > > On Fri, Aug 5, 2011 at 2:09 PM, saurabh singh wrote: >> >> use maps for implementation

Re: [algogeeks] Re: remove duplicate words in a string

2011-08-05 Thread Amol Sharma
@ankit: agree with ankit..hash table or O(n^2) if no extra space -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad On Fri, Aug 5, 2011 at 1:39 AM, ankit sambyal wrote: > If no extra memory is allowed, then I think we can't do better than O(n^2), > which i

Re: [algogeeks] Re: remove duplicate words in a string

2011-08-05 Thread vaibhav shukla
provide a solution whether greater than O(n) On Fri, Aug 5, 2011 at 2:09 PM, saurabh singh wrote: > use maps for implementation of hash table... > if no extra memory allowed then no possible solution within o(n) i > think. > > > On Fri, Aug 5, 2011 at 2:07 PM, ankit sambyal wrote: > >> First

Re: [algogeeks] Re: remove duplicate words in a string

2011-08-05 Thread ankit sambyal
If no extra memory is allowed, then I think we can't do better than O(n^2), which is pretty straight forward. -- 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

Re: [algogeeks] Re: remove duplicate words in a string

2011-08-05 Thread saurabh singh
use maps for implementation of hash table... if no extra memory allowed then no possible solution within o(n) i think. On Fri, Aug 5, 2011 at 2:07 PM, ankit sambyal wrote: > First traverse the string and hash each word into a hash table if it is not > present in the hash table. > Then again t

Re: [algogeeks] Re: remove duplicate words in a string

2011-08-05 Thread ankit sambyal
First traverse the string and hash each word into a hash table if it is not present in the hash table. Then again traverse the string and hash each word. If the word is not present in the hash table, output it to the console. -- You received this message because you are subscribed to the Google G

Re: [algogeeks] Re: remove duplicate words in a string

2011-08-05 Thread vaibhav shukla
sorry one more constraint : no extra memory On Fri, Aug 5, 2011 at 2:03 PM, payel roy wrote: > Hash table ??? > > On 5 August 2011 13:58, vaibhav shukla wrote: > >> give it in C/C++ >> >> >> On Fri, Aug 5, 2011 at 1:57 PM, aj wrote: >> >>> you can write a python program to do that easily. >>>

[algogeeks] Re: remove duplicate words in a string

2011-08-05 Thread amit karmakar
Using a trie data structure this can be solved in O(n). read each character of the input string and build a trie. Maintain the counts of all words. Now traverse the trie again with the input string and making decisions whether to print a string depending on the word count that you get from the tri

Re: [algogeeks] Re: remove duplicate words in a string

2011-08-05 Thread payel roy
Hash table ??? On 5 August 2011 13:58, vaibhav shukla wrote: > give it in C/C++ > > > On Fri, Aug 5, 2011 at 1:57 PM, aj wrote: > >> you can write a python program to do that easily. >> >> program starts here : >> >> c=str.split(raw_input()) >> d=[] >> for x in c: >> d[x]=0 >> print li

Re: [algogeeks] Re: remove duplicate words in a string

2011-08-05 Thread vaibhav shukla
give it in C/C++ On Fri, Aug 5, 2011 at 1:57 PM, aj wrote: > you can write a python program to do that easily. > > program starts here : > > c=str.split(raw_input()) > d=[] > for x in c: > d[x]=0 > print list(d) > > -- > You received this message because you are subscribed to the Google

[algogeeks] Re: remove duplicate words in a string

2011-08-05 Thread aj
you can write a python program to do that easily. program starts here : c=str.split(raw_input()) d=[] for x in c: d[x]=0 print list(d) -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@