Example 1 · empty
- Arguments
- text
""
- Expected return
0
Test data
- Input
{"text":""}- Expected output
0
func LongestDistinct(text string) intExamples use {"text": "..."}.
The runner calls your functions directly; you do not need to parse JSON.
""
0
{"text":""}0
"abcd"
4
{"text":"abcd"}4
"abcaef"
5
{"text":"abcaef"}5
"zzzzz"
1
{"text":"zzzzz"}1
Before each extension, the window has no repeated character. Only the newly added character can violate that invariant. Moving left past its last occurrence removes exactly that conflict; taking the maximum prevents left from moving backward when the old occurrence was already outside the window. The longest valid window ending at each position is considered.
O(n) time for n characters and O(1) auxiliary space using a fixed ASCII last-seen table. A map holds at most the 95 allowed printable ASCII characters, so it is also bounded independently of n.
Checking execution availability…
View inputs and expected outputs. Examples do not run your code.