Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of Longest Substring Without Repeating Characters #2110

Open
adwityac opened this issue Oct 11, 2024 · 2 comments
Open

Addition of Longest Substring Without Repeating Characters #2110

adwityac opened this issue Oct 11, 2024 · 2 comments

Comments

@adwityac
Copy link

Problem Statement

Given a string, your task is to determine the length of the longest substring that does not contain any repeating characters. A substring is defined as a contiguous sequence of characters within a string.

Describe the solution you'd like

The solution to finding the longest substring without repeating characters employs a sliding window approach. We use a dictionary to track the last index of each character while iterating through the string.

As we encounter each character, we check if it has appeared before and whether its last index is within the current substring's bounds. If it has, we move the starting index of our substring to one position right of its last occurrence. We then update the character's last index in the dictionary and calculate the current substring length. If this length exceeds our previously recorded maximum length, we update it.

By the end of the traversal, the maximum length will represent the longest substring without repeating characters. This method runs in linear time, O(n), making it efficient for large strings.

Language: Python

Copy link

Hi 😄, @adwityac Thanks for creating issue at AlgoTree, do read and follow the Code of Conduct and the Contribution Guidelines while contributing. Refer to PR's which has been merged earlier in AlgoTree Click Here Like, How many File they have changed?, Which type of files need to be change? and many more.

Copy link

Hi 😄, thanks for creating issue at AlgoTree, do read and follow the Code of Conduct and the Contribution Guidelines while contributing.

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

No branches or pull requests

1 participant