Problem · String
Valid Mixed Case Letters
Learn this problemProblem 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) → intExamples
Example 1
letters = "aaBCabBC"return = 1Only
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 = 5The 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 = 0There 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
- Maximum Pipeline ThroughputOA · Seen Jul 2026
- Maximum Strong Team SubarrayOA · Seen Jul 2026
- Minimum Cost K-Capable ModelsOA · Seen Jul 2026
- Alphabetically Smallest PalindromeOA · Seen Jul 2026
- Maximum Reward PointsOA · Seen Jul 2026
- Maximum Strength of Every NeuronOA · Seen Jul 2026
- Neural Network Subnetwork StrengthOA · Seen Jul 2026
- XOR MultiplicationOA · Seen Jul 2026