Best way to start is writing down the problem on paper and figure out the solution.
So you have an row of for example characters like so:
0 1 2 3 4 5 6 7 8 9
a h K ; a , a K h k
I would start at the beginning with 'a', then the best way to find the greatest 'distance' for an equal character would be to look for it from the end of the row. For 'a' this would be position 6, so the current maximum distance is 5.
Now onto the next character 'h', which can be found from the end on position 8. So now 'h' becomes the new largest distance of 6.
You continue this way until you reach the end of the row at which time you now the character with the largest 'distance'.
You can implement this by the use of two loops, one which start at the beginning and goes to the end. The second start at the end until it find the character you are looking for.
Each time you find the character in the second you check if the distance is greater than the one you already found and if so make that the new largest one.
I hope this helps you to code the solution your problem.
I gave no code because if you want to learn it is best to do it yourself.