FastPrepLongest Substring Without Repeated Characters
Problems/Longest Substring Without Repeated Characters

Longest Substring Without Repeated Characters

The Walt Disney Company logoThe Walt Disney Company● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The backend tasks included: "LC3".

The report does not give the character set or input bounds. Here, strings may be empty and contain at most 2000 printable ASCII characters; letter case matters.

The judged task matches the report at about 85%.

Given a string s, return the largest length of a contiguous substring in which every character is different.

A substring uses consecutive positions. Spaces, punctuation, digits, uppercase letters, and lowercase letters count as distinct characters. The empty string has answer zero.

Function

lengthOfLongestSubstring(s: String) → int

Examples

Example 1

s = "abcaef"return = 5

The substring bcaef has five different characters. A longer substring would be the whole six-character string, which repeats a. Return 5.

Example 2

s = "cccc"return = 1

Every substring of length two or more repeats c. A one-character substring is valid, so return 1.

Constraints

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

More The Walt Disney Company problems

  • Find All Paths for a Name in a File SystemPHONE SCREEN · Seen Nov 2026
  • Resizable Array-Backed Integer SetPHONE SCREEN · Seen Sep 2026
  • Shortest Path with Directional Move CostsPHONE SCREEN · Seen Sep 2026
All The Walt Disney Company interview questionsSee The Walt Disney Company hiring insights
Saved
class Solution {
    public int lengthOfLongestSubstring(String s) {
        // Write your code here
    }
}
Checking account…