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

Longest Substring Without Repeated Characters

Datadog logoDatadog● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for a longest substring with no repeated characters. Returning its length, the character range, empty input, examples, and limits are specified for practice. The judged core task matches the report at about 90%.

Given s, return the length of its longest substring containing no repeated character.

A substring is a contiguous part of the string. Matching is case-sensitive, and spaces and punctuation count as characters. Return 0 for an empty string.

Function

longestUniqueSubstring(s: String) → int

Examples

Example 1

s = "abcabcbb"return = 3

abc is a substring with three different characters. Any substring of length four contains a repeated character, so the maximum length is 3.

Example 2

s = "abba"return = 2

The substrings ab and ba both have length 2 with no repeated character. Both length-three substrings repeat a character, so the answer is 2.

Example 3

s = "a b a"return = 3

A space counts as a character. The substring a b has three different characters. Every substring of length four contains two spaces, so the answer is 3.

Constraints

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

More Datadog problems

  • Query Log MatchPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Delete a Filesystem TreePHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Grouped-Query Attention Forward PassPHONE SCREEN · Seen Jun 2026
All Datadog interview questionsSee Datadog hiring insights
Saved
public int longestUniqueSubstring(String s) {
    // Write your code here.
}
Checking account…