@Ankur
In a trie u first insert the first word ..take the second word..If its
not
present in the trie u insert it else remove it from original string:
removing the word requires left shifting the entire string
Alternatively u store the elements in a trie in the initial string and
terminate it
a)
1. could split the string using a regexp (into an array) in which you
define a word -- is hi. the same as hi, and hi ?
2. then perform a unique operation on the array (some languages have
this built in) to remove duplicates
3. recombine array elements into string by joining with a space,
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
give it in C/C++
On Fri, Aug 5, 2011 at 1:57 PM, aj aj.jaswa...@gmail.com 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
Hash table ???
On 5 August 2011 13:58, vaibhav shukla vaibhav200...@gmail.com wrote:
give it in C/C++
On Fri, Aug 5, 2011 at 1:57 PM, aj aj.jaswa...@gmail.com wrote:
you can write a python program to do that easily.
program starts here :
c=str.split(raw_input())
d=[]
for x in c:
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
sorry one more constraint : no extra memory
On Fri, Aug 5, 2011 at 2:03 PM, payel roy smithpa...@gmail.com wrote:
Hash table ???
On 5 August 2011 13:58, vaibhav shukla vaibhav200...@gmail.com wrote:
give it in C/C++
On Fri, Aug 5, 2011 at 1:57 PM, aj aj.jaswa...@gmail.com wrote:
you
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
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 ankitsamb...@gmail.comwrote:
First traverse the string and hash each word into a hash table if it is not
present in the hash
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
provide a solution whether greater than O(n)
On Fri, Aug 5, 2011 at 2:09 PM, saurabh singh saurab...@gmail.com 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
@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 ankitsamb...@gmail.comwrote:
If no extra memory is allowed, then I think we can't do better
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 vaibhav200...@gmail.com wrote:
provide a solution whether greater than O(n)
On Fri, Aug 5, 2011 at 2:09 PM, saurabh singh saurab...@gmail.com
these are the final requirements
Remove duplicate words, no extra space,
On Fri, Aug 5, 2011 at 2:12 PM, Gaurav Menghani
gaurav.mengh...@gmail.comwrote:
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
static int array[256];
removedupli(char s[],int n)
{
array[s[0]]=1;
for(i=1;in;i++)
{
if(array[s[i]]==0)
array[s[i]]=1;
else
{
for(pos=i;in;i++)
s[pos]=s[pos+1];
i--;
}
}
}
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this
Can you please explain this?
Is array[256] not extra space?
On Fri, Aug 5, 2011 at 5:14 PM, deepikaanand swinyanand...@gmail.comwrote:
static int array[256];
removedupli(char s[],int n)
{
array[s[0]]=1;
for(i=1;in;i++)
{
if(array[s[i]]==0)
array[s[i]]=1;
else
{
for(pos=i;in;i++)
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
@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 swinyanand...@gmail.comwrote:
ya an array of 256 is surely a wastage of space but this was i couls
18 matches
Mail list logo