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

Create potd_11_10_2024.py #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Faizalimam990
Copy link

Longest Substring Without Repeating Characters

Problem Statement

This pull request introduces the problem statement for the "Longest Substring Without Repeating Characters" challenge. The objective is to find the length of the longest substring without repeating characters in a given string s.

Examples

  1. Input: s = "abcabcbb"
    Output: 3
    Explanation: The longest substring is "abc", with the length of 3.

  2. Input: s = "bbbbb"
    Output: 1
    Explanation: The longest substring is "b", with the length of 1.

  3. Input: s = "pwwkew"
    Output: 3
    Explanation: The longest substring is "wke", with the length of 3.

Constraints

  • 0 <= s.length <= 5 * 10^4
  • s consists of English letters, digits, symbols, and spaces.

Solution

This solution employs the sliding window technique to efficiently find the length of the longest substring without repeating characters.

Implementation

def length_of_longest_substring(s: str) -> int:
    char_set = set()
    left = 0
    max_length = 0
    
    for right in range(len(s)):
        while s[right] in char_set:
            char_set.remove(s[left])
            left += 1
        char_set.add(s[right])
        max_length = max(max_length, right - left + 1)
    
    return max_length
## Fixes: #[issue_number] (replace with the issue number, if applicable)

## Type of Change

- [x] Question Added
- [x] Solution Added
- [ ] Other (please specify):

## How to Test

To test the changes, follow these steps:

1. Clone the repository.
2. Run the provided code in a Python environment.
3. Test with various input strings to ensure correctness.

## Checklist

- [ ] I have performed a self-review of my code.
- [ ] I have commented my code, particularly in hard-to-understand areas.
- [ ] I have made corresponding changes to the documentation (if applicable).
- [ ] My changes generate no new warnings.
- [ ] I have added tests to cover my changes (if applicable).
- [ ] All new and existing tests pass.

added question Longest Substring Without Repeating Characters and solution in python
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, @Faizalimam990! Thanks for creating the pull request.
Soon the maintainers/owner will review it and provide you with feedback/suggestions.
Make sure to star this awesome repository and follow the account!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant