String duplicate and count | SoloLearn: Learn to code for FREE!

0

String duplicate and count

Question is Input is String s= aaabbbccc; Output is a3b3c3 Test case 2: Input is String s=aaaabbccc; Output is a4b2c3 Can u suggest me a code Or give clues to write code for that

3/11/2020 4:57:57 AM

Haritha Vuppula

3 Answers

New Answer

0

An outline would be- 1. Iterate through the string. 2. When a new letter is found, add the letter to the output string and then add the count of the letter in the string to the output string.

0

No i tried but i didnt getting logic for count can u please tell me code

0

Can you show your attempt pls? You are already asked similar question.. So can code with information from that. Give a try, You can convert to char array or use charAt() method... Read string in a loop, if i'th char ==i+1 char increase count, continue Else print i'th char and count, reset count=0, then continue with next charecters... If you struck between, then share code,...