Problem · String

Valid Mixed Case Letters

Learn this problem
EasyMicrosoftFULLTIMEOA
See Microsoft hiring insights

Problem statement

You are given a string letters consisting of N English alphabet characters.

Count the distinct letters for which both lowercase and uppercase forms occur and at least one lowercase occurrence appears before a later uppercase occurrence of the same letter.

Complete solution(String letters) and return the count as an integer.

🐹 Source note (Jul 17, 2026): The first two example answers did not agree with their inputs and the intended ordering rule. The rule and answers are now stated consistently. The judged core task matches the source intent at about 98%.

Function

solution(letters: String) → int

Examples

Example 1

letters = "aaBCabBC"return = 1
Only b qualifies because a lowercase b appears before a later uppercase B. The letter a has no uppercase form, and c has no lowercase form.

Example 2

letters = "xyzXYZabCABc"return = 5
The letters x, y, z, a, and b qualify. The lowercase c appears only after the uppercase C, so c does not qualify.

Example 3

letters = "ABCcaBcEfg"return = 0
There are no letters that appear in both lowercase and uppercase forms where all lowercase occurrences appear before their uppercase occurrences. Therefore, the output is 0.

Constraints

See above 🐳

More Microsoft problems

drafts saved locally
public int solution(String letters) {
  // write your code here
}
letters"aaBCabBC"
expected1
checking account