Python function find_longest_substring(s)
Write a Python function find_longest_substring(s)
that takes a string s
and returns the longest substring without repeating characters. If there are multiple substrings of the same maximum length, return the first one.
Example:
python
Example input:
s = abrkaabcdefghijjxxx
Expected output:
longest_substring = abcdefghij
Constraints:
- The input string
s
will only contain lowercase English letters. - The function should run efficiently even for long strings (up to 10,000 characters).
Test Cases:
python
Test Case 1:
assert find_longest_substring(“abcabcbb”) == abc
Test Case 2:
assert find_longest_substring(“bbbbb”) == b
Test Case 3:
assert find_longest_substring(“pwwkew”) == wke
Test Case 4:
assert find_longest_substring(“abcddefg”) == abcdefg
Test Case 5:
assert find_longest_substring(“anviaj”) == nviaj
Write thefind_longest_substring
function that passes all the above test cases.