Skip to content

Conversation

@akxavier
Copy link
Contributor

The length of the substring doesn't decrease - it either stays the same (when the condition (r - l + 1) - maxf > k is true and we increment l) or increases otherwise. Hence once it reaches the maximum substring value, it never goes down. So instead of taking max(res, r - l + 1) in each iteration, just return the value (r - l + 1) at the end of the loop.

Important

Please make sure the file name is lowercase and a duplicate file does not already exist before merging.

The length of the substring doesn't decrease - it either stays the same (when the condition (r - l + 1) - maxf > k is true and we increment l) or increases otherwise. Hence once it reaches the maximum substring value, it never goes down. So instead of taking max(res, r - l + 1) in each iteration, just return the value (r - l + 1) at the end of the loop.
@tahsintunan tahsintunan merged commit 8673546 into neetcode-gh:main Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants