FastPrepLongest Substring Without Repeating Characters
Problems/Longest Substring Without Repeating Characters

Longest Substring Without Repeating Characters

AMD logoAMD● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interviewer asked: "The classic LeetCode 3."

The report gives no input limits or examples. Here, the string uses printable ASCII characters, comparisons are case-sensitive, and the result is the longest length.

The judged task matches the report at about 90%.

Given a string s, return the length of its longest contiguous substring with no repeated character. Character comparisons are case-sensitive. A substring must use consecutive characters; a subsequence does not qualify. Return 0 for the empty string.

Function

lengthOfLongestSubstring(s: String) → int

Examples

Example 1

s = "abcabcbb"return = 3

abc is a valid substring of length 3. Every substring of length 4 contains a repeated character.

Example 2

s = "bbbbb"return = 1

A single b is valid. Every longer substring repeats b.

Example 3

s = ""return = 0

The empty string has no characters, so the longest length is 0.

Constraints

  • 0 <= s.length <= 100000.
  • Every character in s is printable ASCII, with a character code from 32 through 126.

More AMD problems

  • Insert After a Linked-List NodeONSITE INTERVIEW · Seen Oct 2026
  • LRU CacheONSITE INTERVIEW · Seen Oct 2026
  • Lowest Common Ancestor of a Binary TreePHONE SCREEN · Seen Oct 2026
All AMD interview questionsSee AMD hiring insights
Saved
public int lengthOfLongestSubstring(String s) {
    return 0;
}
Checking account…