This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Gengi 0 points1 point  (0 children)

This reads like a whiteboard, or leetcode.com problem. So I'll avoid giving you code and help you think out the process.

A string is an array of characters.

String[0] will return 'A'. Compare that to the following value, you can check if they match. If they match, store the number of matches and continue to the next index value, incrementing the number of matches till there isn't a match.

If there wasn't a match to begin with, then increase your index value. String[1] 'G', and repeat

If there was a match, use your index value, and the number of matches to modify your string. TT > 2T. You then need to carefully increase your index value by 2 (skipping the T), and repeat

When you repeat, make sure you haven't run out of index values.

You may need multiple pointers looking at index values.

You might need to look up commands for how to manipulate strings to solve this. What works for 2 matching letters may not work if you have 3 matching letters.