You can make use of an auxiliary array(initialized to 0) to store the count of each char and then print it that many times. char inp[]="abcdaabcdefe"; int buff[256]={0};
for(int i=0;i<strlen(inp);i++) buff[inp[i]]++; for(int j=0;j<256;j++) while(buff[j]--) cout<<(char)j; On Wed, Jun 22, 2011 at 10:27 AM, Sriganesh Krishnan <2448...@gmail.com>wrote: > Input will be a string. We need to o/p a string with the order of > characters same as the input but with same characters grouped together. > I/P: abcdacde > O/P: aabccdde > > I/P: kapilrajadurga > O/P: kaaaapilrrjdug > > I/P: 1232 > O/P: 1223 ……………….. O(n) time……….. O(1) space……………. > > > how can you approach these type of string related problems, is there any > specific technique involved? > > -- > 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. > -- Harshal Choudhary, Final Year B.Tech CSE, NIT Surathkal, Karnataka, India. -- 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.