All practice tasks

Coding (Algo)

Longest Distinct Run

Sliding window · Medium

A diagnostic tool scans a sequence of one-character event codes. It highlights the longest uninterrupted run in which no code appears twice. This is a string exercise, not a parser for logs or Unicode graphemes.

Return the length of the longest contiguous substring of s with no repeated characters.

Input

Call

  • Implement solve(input) and return the result. The provided adapter handles JSON input and output.

Input shape

A JSON object { "s": string }.

Fields

  • s is a string of printable ASCII characters, including spaces. Uppercase and lowercase codes are different.

Output

Return value

  • Return the length, not the substring. Tied substrings require no tie-break because their lengths are equal.
  • The selected characters must be adjacent in s.
  • An empty string returns 0.

Constraints

  • 0 <= s.length <= 100000.
  • Characters have ASCII codes 32..126; Unicode normalization is outside this task.

Examples

Example 1

{
  "s": "abba"
}

Returns

2

ab and ba are valid; abb is not.

Example 2

{
  "s": "Aa bA"
}

Returns

4

A, a, space and b form a valid length-four run.

Required complexity

O(n) time and O(95) extra space

What this task practices

Longest Distinct Run is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as medium difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.