FastPrepCount Repeated Letter Occurrences
Problems/Count Repeated Letter Occurrences

Count Repeated Letter Occurrences

AMD logoAMD● EasyINTERNONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report mentions counting similar or repeated letters without defining the counting convention. This practice explicitly counts occurrences after the first; the alphabet, bounds and interface are authored. Approximate source match 70%. An exact source date is not available.

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) → int

Examples

Example 1

s = "abaca"return = 2

The a letters at indices 2 and 4 repeat the a at index 0.

Example 2

s = "aaa"return = 2

The 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.
All AMD interview questionsSee AMD hiring insights
Saved
public int repeatedLetterCount(String s) {
    // Write your code here.
}
Checking account…