A warehouse security log is a string of lowercase letters, where each letter is a badge code scanned at a checkpoint, recorded in the order the scans happened during a shift.
Some badge codes end up being scanned an even number of times over the shift, and some an odd number of times. Let A be the highest scan count among all badge codes that were scanned an even number of times, and let B be the lowest scan count among all badge codes that were scanned an odd number of times.
Compute A - B.
A single line containing the log string s of lowercase English letters.
A single integer: A - B.
s <= 100s consists only of lowercase English letters ('a' to 'z').s contains at least one badge code with an even scan count and at least one badge code with an odd scan count.Example 1
Input
aaaabbc
Expected
3
Explanation
Frequencies: a=4 (even), b=2 (even), c=1 (odd). The largest even frequency is 4 (a), the smallest odd frequency is 1 (c). Answer = 4 - 1 = 3.
Example 2
Input
abcabcab
Expected
-1
Explanation
Frequencies: a=3, b=3, c=2. Only c has an even frequency (2), so the even-max is 2. Both a and b have odd frequency 3, so the odd-min is 3. Answer = 2 - 3 = -1, showing the result can be negative.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →