Re: [algogeeks] character count in array

2011-09-04 Thread sarath prasath
here is my approach
where i left the non repeating characters as it is and done some good code..
char * runlengthencode(char* str,int size)
{
int i,j,flag=0;
for(i=0,j=1;str[i]str[j]jsize;i++,j++)
{
while(str[i]==str[j])
{
j++;
flag=1;

}
if(flag)
{
j=j-1;
str[i+1]=48+(j-i+1);
flag=0;
i=j;
j++;
}
}
return str;
}

On Sat, Sep 3, 2011 at 6:54 PM, Aman Kumar amanas...@gmail.com wrote:

 Hiii
 if array is given like this

 arr[]=aabcabbcdeadef

 convert this array into like

 arr[]=a4b3c2d2e2f1

 how can we do this

 can we do it with space complexity O(1).

 reply asap

 --
 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] character count in array

2011-09-03 Thread rajul jain
use hashing but you dont get space O(1) in hashing

On Sat, Sep 3, 2011 at 6:54 PM, Aman Kumar amanas...@gmail.com wrote:

 Hiii
 if array is given like this

 arr[]=aabcabbcdeadef

 convert this array into like

 arr[]=a4b3c2d2e2f1

 how can we do this

 can we do it with space complexity O(1).

 reply asap

 --
 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] character count in array

2011-09-03 Thread priya ramesh
use hashing

-- 
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] character count in array

2011-09-03 Thread Piyush Grover
use hashing u'll get O(1) space..
@rahul...why not??

On Sat, Sep 3, 2011 at 7:13 PM, priya ramesh love.for.programm...@gmail.com
 wrote:

 use hashing

 --
 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] character count in array

2011-09-03 Thread teja bala
this 'll work if u i/p the string in dis manner
aaabbcc(consecutive same)
a3b2c2

#includestdio.h
#includeconio.h
main()
{
int x=1,i=0;
char a[100];
gets(a);
while(a[i]!='\0')
{
 while(a[i]==a[i+1])
 {
x++;
i++;
 }
 printf(%c%d,a[i],x);
 x=1;
 i++;
 }
getchar();
}

-- 
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.