Longest Substring Without Repeating Characters
Problem statement
Given a string text, return the length of its longest contiguous substring in which every character is distinct.
A substring keeps consecutive characters in their original order. Uppercase and lowercase letters are different characters, and spaces and punctuation also count. The empty string has answer 0.
Function
lengthOfLongestSubstring(text: String) → intExamples
Example 1
text = "abcabcbb"return = 3The substring abc has three distinct characters; no longer substring qualifies.
Example 2
text = "abba"return = 2Either ab or ba has length two. The repeated letters cannot be skipped.
Example 3
text = ""return = 0An empty string contains no nonempty substring.
Constraints
0 <= text.length <= 10000.- Every character is printable ASCII, with code from
32through126.