greedy_methods.sliding_window¶
Functions¶
|
This function takes a string and returns the length of the longest substring |
Module Contents¶
- greedy_methods.sliding_window.sliding_window(input_string: str) int¶
This function takes a string and returns the length of the longest substring without repeating characters using the sliding window algorithm.
It runs in O(n) time, where n is the length of the string. The sliding window approach ensures that each character is processed at most twice.
- Args:
input_string: A string input.
- Returns:
int: Length of the longest substring without repeating characters.
- Raises:
TypeError: If the input is not a string.
Examples: >>> sliding_window(“abcabcbb”) 3 >>> sliding_window(“bbbbb”) 1 >>> sliding_window(“pwwkew”) 3 >>> sliding_window(“”) 0 >>> sliding_window(“abcdefg”) 7 >>> sliding_window(“abccba”) 3 >>> sliding_window(“a”*10000) 1