- Notifications
You must be signed in to change notification settings - Fork2.4k
Open
Description
Bug Report forhttps://neetcode.io/problems/longest-repeating-substring-with-replacement
- The second hint states that
It is always optimal to replace characters with the most frequent character in the string.
- This is intuitive, but not correct.
- Consider the following example:
- the input stirng:
ABACADAEEAEEAFAGAH
and k = 1 - If the tip were to be followed, the only character worth replacing with would be
A
, the one with the highest frequency, resulting in the maximum possible length equal to 3 - Instead, the character worth replacing is the A in the middle of the group of Es with another E. Doing this will result in the length 5 and the correct answer
- the input stirng:
Metadata
Metadata
Assignees
Labels
No labels