Minimum Deletions to Make Every Letter Count Even
Updated
Problem statement
You may delete any characters from a lowercase string S. Find the minimum number of deletions needed so that every letter remaining in the string occurs an even number of times.
An absent letter has count zero, which is even. The empty string therefore satisfies the condition.
Function
solution(S: String) → intExamples
Example 1
S = "acbcbba"return = 1Removing one b leaves every count even.
Example 2
S = "axxaxa"return = 2Remove one a and one x to make both letter counts even.
Example 3
S = "aaaa"return = 0The four a characters already have an even count.
Constraints
0 <= S.length <= 200000.Scontains only lowercase English letters.
More Marshall Wace Online Assessment questions
- Count Letters with Ordered Lowercase and Uppercase OccurrencesOA · Seen Oct 2025
- Maximum Trailing Zeros on a Path with at Most One TurnOA · Seen Oct 2025
- Shortest Subarray Covering an Integer RangeOA · Seen Oct 2025
- Maximum Events in a 60-Second WindowOA · Seen Aug 2025
- Successful Logins from Multiple CountriesOA · Seen Aug 2025
- Maximize Remaining Item Types After Clearing Consecutive ShelvesOA · Seen Nov 2024
- Shortest String After Erasing Equal PairsOA · Seen Nov 2024
- Count Distinct Tags in a Fixed-Radius Circle (Practice Reconstruction)OA · Seen Apr 2024
- Generate Unique Company Email AddressesOA · Seen Apr 2024
- Reconstruct a Two-Row Binary MatrixOA · Seen Apr 2024
Similar questions at other companies
- Count Phrases Formed by Anagram ReplacementWells Fargo · OAWells Fargo interview questions
- Ransom NoteThe Walt Disney Company · OA · PHONE SCREENThe Walt Disney Company interview questions
- Count One-Swap Number PairsCapital One · OACapital One interview questions
- How Many Sentences?Chubb · OAChubb interview questions
- Perfect SubstringsVisa · OAVisa interview questions
- Cheating CodemakerJane Street · OAJane Street interview questions
- Count Equal-Frequency SubsequencesExpedia · OAExpedia interview questions
- How Many Sentences?Atlassian · OAAtlassian interview questions
- K-th Non-Repeating Character IndexBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Dictionary Words Formable From LettersGoogle · ONSITE INTERVIEWGoogle interview questions