Count Repeated Letter Occurrences
Problem statement
Count the character positions whose letter has appeared earlier in s. Each letter contributes zero for its first occurrence and one for every later occurrence.
For example, three occurrences of one letter contribute two, rather than one distinct repeated letter or three total occurrences.
Function
repeatedLetterCount(s: String) → intExamples
Example 1
s = "abaca"return = 2The a letters at indices 2 and 4 repeat the a at index 0.
Example 2
s = "aaa"return = 2The first a is new; the next two a letters are repeats.
Constraints
0 <= s.length <= 2000.- s contains only lowercase English letters a through z.