17. Longest Substring Without Repeating Characters

17. Longest Substring Without Repeating Characters

Medium
45.0%
1.9k
stringhash-tabletwo-pointerssliding-window
Google, Amazon, Netflix, Meta (Facebook), Apple, Microsoft, Uber, Bloomberg, Airbnb, Stripe, Adobe, Salesforce, LinkedIn, Oracle

You’re interviewing for a backend or data engineering role at a FAANG-level company. The interviewer describes a real product scenario:

A large streaming, search, or marketplace platform analyzes user interaction logs. Each session produces a string that represents a sequence of actions or identifiers, such as:

  • page clicks or feature usage codes
  • search query characters typed over time
  • event keys in a stream
  • tokens in a request trace

To detect healthy behavior patterns and reduce fraud, the platform needs to find the longest continuous segment of activity where no identifier repeats.

The session log is represented as a string s. The platform wants the length of the longest substring that contains no repeating characters.

This is a common practice coding problem for DSA question might ask in Google, Amazon, Netflix, Meta, Apple, Microsoft, Uber, and Bloomberg interviews.

Your Task

Given a string s, return the length of the longest substring without repeating characters.

A substring must be contiguous, meaning characters must come from consecutive positions in the string.

Input Format

  • s: a string (can include letters, digits, symbols, and spaces)

Output Format

  • A single integer representing the maximum length of a substring without repeating characters

Examples

Example 1:

Input: s = "abcabcbb"
Output: 3

Example 2:

Input: s = "bbbbb"
Output: 1

Example 3:

Input: s = "pwwkew"
Output: 3

Constraints

  • 0 <= s.length <= 100,000
  • s may contain English letters, digits, symbols, and spaces

Loading editor...

"abcabcbb"
3

Console Output

Click "Run Code" or "Submit" to see results

Your code will be evaluated by AI with instant feedback