MicrosoftOA #16
Count Characters Before Uppercase
Estimated EasyJudge-ready
Consider only the text strictly before the first uppercase English letter, and count the distinct lowercase English letters in it; if there is no uppercase letter, consider the whole text. Under this definition, the original site's example aaAbcCABBc should give 1; this site has corrected it.
Input
This site's input: one line of printable ASCII text of length 0..100000, which may contain spaces; only A..Z and a..z count as letters.
Output
Output a single integer, the answer.
Example 1
Input:
aaAbcCABBc
Output:
1
Example 2
Input:
abca
Output:
3
Example 3
Input:
XYZ
Output:
0
Example notes
Example 1: only aa comes before the first uppercase A, and its only distinct lowercase letter is a; the answer is 1.
Example 2: there is no uppercase letter, and the distinct lowercase letters in the whole text are a, b, c; the answer is 3.
Example 3: the first character is already uppercase, so the prefix is empty; the answer is 0.
Editorial
Loading solution…