As reported: Bloomberg Software Engineering intern (London, 2025), technical intro (60 minutes, half on background): a question very similar to LeetCode 1941 — check whether all characters have the same number of occurrences — with a rule added later: you may also remove one character to make the string valid. Return true or false.
This builds on LeetCode 1941 — Check if All Characters Have Equal Number of Occurrences.
A string is valid if every letter that appears in it appears the same number of times. Given s, return true if s is valid, or becomes valid after deleting one character (one occurrence of one letter).
Example 1
s = "abacbc"
Output: true (a, b and c appear twice each)
Example 2
s = "aabbc"
Output: true (delete the c)
Example 3
s = "aaabb"
Output: true (delete one a)
Example 4
s = "aabbcd"
Output: false
Constraints: 1 ≤ s.length ≤ 10^5; s contains lowercase English letters.
Clarifications
- The deletion is optional: a string that is already valid returns
true. - If the deleted character was the only occurrence of its letter, that letter no longer appears and is not counted.
Code runner format: one JSON value per line: s. Implement isValid(s); the harness prints true or false.