Problem · String

Longest Substring Without Repeating Characters

Learn this problem
MediumByteDance logoByteDanceFULLTIMEPHONE SCREEN

Problem statement

Given a string text, return the length of its longest contiguous substring whose characters are all distinct.

The empty string has answer 0.

Function

lengthOfLongestSubstring(text: String) → int

Examples

Example 1

text = "abcabcbb"return = 3

abc is a longest substring with no repeated character.

Example 2

text = "pwwkew"return = 3

wke has length three. The answer concerns a contiguous substring, not a subsequence.

Constraints

  • 0 <= text.length() <= 100000
  • text contains only printable ASCII characters.

More ByteDance problems

drafts saved locally
public int lengthOfLongestSubstring(String text) {
    // Write your code here.
}
text"abcabcbb"
expected3
checking account