Write an algorithm to find the longest substring without repeating characters.
Implement the function below. Given a string s, return the length of its longest contiguous substring in which every character appears at most once. Return 0 for an empty string. The solution should run in linear time.
Function: length_of_longest_substring(s)
Example: s = "abcabcbb" returns 3, because "abc" is the longest valid substring.
def length_of_longest_substring(s):