FastPrepLongest Substring Without Repeating Characters

Longest Substring Without Repeating Characters

Amazon logoAmazon● MediumNEW GRADINTERNONSITE INTERVIEW

Problem statement

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

Function

lengthOfLongestSubstring(s: String) → int

Examples

Example 1

s = "abcabcbb"return = 3

abc is a longest substring with no repeated character.

Example 2

s = "bbbbb"return = 1

Every distinct-character substring contains at most one b.

Example 3

s = ""return = 0

The empty string has no nonempty substring.

Constraints

  • 0 <= s.length <= 200000.
  • s contains printable ASCII characters.

More Amazon problems

See Amazon hiring insights
Saved
public int lengthOfLongestSubstring(String s) {
    // Write your code here.
}
s"abcabcbb"
expected3
Checking account…