Valid Mixed Case Letters
Updated
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.
Function
solution(letters: String) → intExamples
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 = 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 interview questions
- Config Store with Priority OverridesPHONE SCREEN · Seen Nov 2026
- Authentication SystemOA · Seen Nov 2026
- Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
- Maximum String OperationsOA · Seen Nov 2026
- Minimum Cost to Process Priority TasksOA · Seen Nov 2026
- Most Visited Sprint MarkerOA · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Branch with the Most FilesCapital One · OACapital One interview questions
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- First Non-Repeating CharacterAmazon · OA · ONSITE INTERVIEW
- Total Each Letter's Count in an Encoded StringIBM · OAIBM interview questions
- Find Words That Can Be Formed by CharactersTabaPay · OA
- Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
- Count Palindrome Addition ChoicesThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
- Count Palindrome Addition ChoicesHudson River Trading · OAHudson River Trading interview questions
- Count Phrases Formed by Anagram ReplacementWells Fargo · OAWells Fargo interview questions
- Count Repeated Request IDs (Data Science OA)McKinsey & Company · OAMcKinsey & Company interview questions
Microsoft interview experiences
- Microsoft OA Questions, October 2026: 4 Experiences
- Microsoft Experienced SWE Phone Screen: 1 Experience
- Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
- Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
- Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
- Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)