Problem · String

Valid Mixed Case Letters

EasyMicrosoftFULLTIMEOA
See Microsoft hiring insights

You are given a string letters consisting of N English alphabet characters (a-z, A-Z).

Your task is to determine how many distinct alphabet letters appear in both lowercase and uppercase, and all of the lowercase occurrences of that letter appear before any of its uppercase occurrences in the string.

Function Signature

Complete the function solution in the editor.

solution has the following parameter:

  1. String letters: a string of English letters (a-z, A-Z)

Input

• A string letters of length N (1 ≤ N ≤ 100,000)
• The string contains only English letters (a-z, A-Z)

Output

• Return an integer representing the number of distinct letters that satisfy the following:

  1. Both the lowercase and uppercase forms of the letter appear in the string
  2. All lowercase occurrences appear before any uppercase occurrence of that letter

Examples
01 · Example 1
letters = "aaBCabBC"
return = 2
Letter 'a' and 'b' satisfy the conditions, but letter 'c' does not.
02 · Example 2
letters = "xyzXYZabCABc"
return = 6
n/a
03 · 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"
expected2
sign in to submit