InferenceAI

Enter at least two characters to search.

Start free

Longest Distinct Window

mediumSliding Window25 min25 XP

Return the length of the longest substring of s in which no character repeats.

Requirements

  • Run in O(n)O(n) time.

Examples

EXAMPLE WALKTHROUGHrepeating pattern

A guided view of the published example, not a trace of your code.

INPUT["abcabcbb"]
TASKlongest_distinct_window()
EXPECTED OUTPUT3

Start with the input values shown in this example.

Example 1 of 3

Input: s = "abcabcbb"

Output: 3

Explanation: repeating pattern

Input: s = "bbbbb"

Output: 1

Explanation: one character

Input: s = "pwwkew"

Output: 3

Explanation: window in the middle

Hint 1

Grow a window to the right; when a character repeats, move the left edge just past its previous position.

Topics

DSASliding WindowPython