1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2024-07-18 02:20:12 +02:00
programming-challenges/challenges/frequency-deviation
2023-10-23 23:16:24 +02:00
..
solutions chore: better Prettier config for easier reviews 2023-10-23 23:16:24 +02:00
test fix(challenges): add 7th, 8th and 9th tests cases for frequency-deviation 2023-09-16 16:36:07 +02:00
README.md feat(challenges): add frequency-deviation 2023-09-16 15:50:35 +02:00

frequency-deviation

Created by @theoludwig on 16 September 2023.

Instructions

Given a string consisting of lowercase English letters, we define the frequency deviation of a substring as the difference between the maximum and the minimum frequencies of the characters in that substring.

A substring of a string is formed by any contiguous segment of the string. For example, given "bbacccc", the character appearing most frequently is 'c' with 4 occurrences. The character that appears the fewest times is 'a' with 1 occurrence. The frequency deviation of the entire string is 4 - 1 = 3.

Given a string, s, representing the input string, find the maximum possible frequency deviation of any of its substrings.

Constraints

  • 1 \leq s.length \leq 10^4
  • s consists of lowercase English letters.

Source

Examples

See the test folder for examples of input/output.

Example 1

Input

bbacccc

Output

3

Example 2

Input

aabb

Output

1

Example 3

Input

aaaaa

Output

0