how can we find 1st repeating character in string???
e.g. if the string is abba it should return 'b' and not 'a'.
note: hashing will give the answer as 'a'
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send
you will have to note time for of occurence of a character for all chars
On Fri, Jun 8, 2012 at 2:15 PM, himanshu kansal himanshukansal...@gmail.com
wrote:
how can we find 1st repeating character in string???
e.g. if the string is abba it should return 'b' and not 'a'.
note: hashing
howcome hashing will result in wrong output..??
if(isHashed(str[i])
{
character found.
break.
}
else
hash(str[i]);
On Fri, Jun 8, 2012 at 2:15 PM, himanshu kansal himanshukansal...@gmail.com
wrote:
how can we find 1st repeating character in string???
e.g. if the string is abba
This is MS Q and hasing will give the right answer. walk over the string,
if it is present in hashTable, it is first repeated character. This is
single pass.
However, if you do another pass, your answer would be a which is first
char that is repeated whereas b is first character to occur first
But you can use unordered map something like what boost does ..
http://boost.cowic.de/rc/pdf/unordered.pdf
Cheers.
On Friday, June 8, 2012 5:38:56 PM UTC+8, ashgoel wrote:
This is MS Q and hasing will give the right answer. walk over the string,
if it is present in hashTable, it is first
In a string try to loop through all character and count the occurances
(incrementing by 1 whenever that character occurs)... store it in hash
(initialize the hash to 0)... when the count of any char equals 2 break
from the loop that char is first repeating char.
-- RK :)
On Fri, Jun 8, 2012 at
Use the below function, that will return first repeated character of
string or null;
Note: blank space is also consider as character... you can add exception to
avoid such case
char firstRepeatChar(char *str)
{
int arr[256] = {0};
for(int i = 0; str[i] != '\0'; i++)
{
arr[str[i]] +=1;
the output will be correct it will not be incorrect in hashing case .
On Fri, Jun 8, 2012 at 2:38 PM, atul anand atul.87fri...@gmail.com wrote:
howcome hashing will result in wrong output..??
if(isHashed(str[i])
{
character found.
break.
}
else
hash(str[i]);
On Fri, Jun
lets say we have an array COUNT[256] which is initialized to zero.
1) traverse the string S from 0 to length-1
2) if COUNT[S[i] - '0'] == 0 , increment COUNT[S[i] - '0'] = 1;
3) else print the first repeating character.
-Mahesh
On Fri, Jun 8, 2012 at 2:26 PM, Anika Jain
you may use look up table for each character like this :
int table[255]={0};
for(int i=0;str[i];i++)
{
if( table[str[i]] )
return true;
else
{
table[str[i]]=1;
}
}
return false;
On Fri, Jun 8, 2012 at 2:26 PM, Anika Jain anika.jai...@gmail.com wrote:
you will have to note
The key doesn't lies in the way it will be solved.It is how efficiently you
implement the hash table.do we really need an integer array ( 4*256 bytes)
just to record the first occurrence of a character?
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com
On Fri,
no hashtable needed , a bitmap is sufficient
Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652
On Fri, Jun 8, 2012 at 4:04 PM, saurabh singh saurab...@gmail.com wrote:
The key doesn't lies in the way it will be solved.It is how efficiently
you
order of hashing and counting is important
eg. abba
if we do hashing by characters 'a' is stored before 'b'
and count of both is 2 at the end and when we process this we give result
'a' (because 'a' comes before 'b' )which is wrong
because 'b' is the first repeated character.
Thanks Regards
@all: my bad...i ws confused while posting the ques.
hashing can gv either a or bonly thing tht matters is hw u implement
hashing and counting
thanx i hv got the soln
On Fri, Jun 8, 2012 at 4:33 PM, Saurabh Yadav saurabh...@gmail.com wrote:
order of hashing and counting is
@saurabh: why would u count all??? just see while counting if the bitmap is
set.. then return the char.
On Fri, Jun 8, 2012 at 4:33 PM, Saurabh Yadav saurabh...@gmail.com wrote:
order of hashing and counting is important
eg. abba
if we do hashing by characters 'a' is stored before 'b'
and
ya...hashing is rt method but, we have to implement it by using self
referential structure
i think ..stilll we can solve this problem by using arrayslike
int arr[256]={0};
int main()
{
char str[]=abba;
.
.
for(i=0;str[i]!=NULL;i++)
{
if(arr[(str[i]-'0')]==1)
{
printf(first
i was explaining the general idea which we generally use with hashing i.e.
hashing and counting the all the char and then find which is the repeated
character
yes u r correct , for the correct solution we should return when we found
bitmap set , which is the actual solution :)
On Fri, Jun 8,
17 matches
Mail list logo