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:
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:
- Both the lowercase and uppercase forms of the letter appear in the string
- All lowercase occurrences appear before any uppercase occurrence of that letter
letters = "aaBCabBC" return = 2
letters = "xyzXYZabCABc" return = 6
letters = "ABCcaBcEfg" return = 0
See above 🐳- Rank Open BusinessesPHONE SCREEN · Seen May 2026
- Retain Top K ValuesPHONE SCREEN · Seen May 2026
- In-Memory SQL with CSV InitializationONSITE INTERVIEW · Seen May 2026
- Order Records by Matching Start and EndONSITE INTERVIEW · Seen May 2026
- Recover Corrupted Master PageONSITE INTERVIEW · Seen Feb 2026
- Get Minimum TimeSeen Jun 2025
- Count Subarrays with Bitwise OR PresentSeen Jun 2025
- Get Max Or SumSeen Jun 2025
public int solution(String letters) {
// write your code here
}