FastPrepLongest Distinct String
Problems/Longest Distinct String

Longest Distinct String

Superhuman logoSuperhuman● MediumNEW GRADINTERNOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The visible source supplies the complete objective and one worked example but omits input bounds and a callable signature. The judged core task matches the screenshot at about 98%.

Given a string s, return the length of its longest contiguous substring in which no character appears more than once.

A substring is a contiguous sequence of characters within s. Return only the maximum length, not the substring itself.

Function

longestDistinctString(s: String) → int

Examples

Example 1

s = "abcc"return = 3

The substring "abc" contains no repeated character and has length 3.

Example 2

s = "abcabcbb"return = 3

Substrings such as "abc" have length 3, and every longer substring repeats a character.

Example 3

s = "bbbbb"return = 1

Every distinct-character substring contains only one b.

Constraints

  • 1 <= s.length <= 100000
  • s contains printable ASCII characters.

Source note: The source slide shows the objective, uniqueness rules, and the worked abcc example.

More Superhuman problems

  • Email Funnel: Opened Within a Day, Replied Within a WeekPHONE SCREEN · Seen Nov 2026
  • Minimum Time on Two ProcessorsOA · Seen Sep 2026
  • Top Mutual-Friend RecommendationsOA · Seen Sep 2026
All Superhuman interview questionsSee Superhuman hiring insights
Saved
class Solution {
    public int longestDistinctString(String s) {
      // Write your code here.
    }

}
Checking account…