#3445

Maximum Difference Between Even and Odd Frequency II

candidate master · 1485 · lc hard +32 · 48.7% accepted · 392 likes · top 35%

Description

You are given a string s and an integer k. Find the maximum difference freq[a] - freq[b] between the frequencies of two characters a and b within some substring subs of s, subject to:

- subs has length at least k.

- Character a has an odd frequency in subs.

- Character b has a non-zero even frequency in subs.

Return the maximum difference.

Note that subs may contain more than 2 distinct characters.

Code

1
2
3