PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates string-processing skills and algorithmic problem-solving, including handling character uniqueness and performance considerations. Commonly asked in Coding & Algorithms interviews to assess a candidate's ability to implement efficient solutions and reason about time/space trade-offs, it targets practical application rather than purely conceptual understanding.

  • Medium
  • Amazon
  • Coding & Algorithms
  • Data Scientist

Determine Length of Longest Unique Substring

Company: Amazon

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

##### Scenario Online assessment: coding portion that follows the SQL questions. ##### Question Implement a function that, given a string s, returns the length of the longest substring without repeating characters. ##### Hints Use a sliding window and a hash map to track the latest index of each character.

Quick Answer: This question evaluates string-processing skills and algorithmic problem-solving, including handling character uniqueness and performance considerations. Commonly asked in Coding & Algorithms interviews to assess a candidate's ability to implement efficient solutions and reason about time/space trade-offs, it targets practical application rather than purely conceptual understanding.

Given a string `s`, return the length of the longest substring of `s` that contains no repeating characters. A substring is a contiguous sequence of characters within the string. The substring must not contain any character more than once. **Examples** - `s = "abcabcbb"` -> `3` (the answer is `"abc"`, length 3). - `s = "bbbbb"` -> `1` (the answer is `"b"`, length 1). - `s = "pwwkew"` -> `3` (the answer is `"wke"`, length 3; note `"pwke"` is a subsequence, not a substring). - `s = ""` -> `0`. Return the integer length of the longest such substring.

Constraints

  • 0 <= len(s) <= 5 * 10^4
  • s consists of English letters, digits, symbols, and spaces.
  • The empty string returns 0.

Examples

Input: ("abcabcbb",)

Expected Output: 3

Explanation: The longest substring without repeats is "abc", length 3.

Input: ("bbbbb",)

Expected Output: 1

Explanation: Every character is the same, so the best is a single "b".

Input: ("pwwkew",)

Expected Output: 3

Explanation: "wke" has length 3; "pwke" is a subsequence, not a substring.

Input: ("",)

Expected Output: 0

Explanation: An empty string has no characters, so the length is 0.

Input: ("a",)

Expected Output: 1

Explanation: A single character is trivially unique.

Input: ("dvdf",)

Expected Output: 3

Explanation: The window jumps past the first 'd' to give "vdf", length 3.

Input: ("abba",)

Expected Output: 2

Explanation: After reaching the second 'a', start must not move backward; "ab" and "ba" each give length 2.

Input: (" ",)

Expected Output: 1

Explanation: A single space counts as a character, length 1.

Input: ("tmmzuxt",)

Expected Output: 5

Explanation: "mzuxt" is the longest unique window, length 5.

Input: ("abcdefg",)

Expected Output: 7

Explanation: All characters distinct, so the whole string qualifies.

Hints

  1. Use a sliding window: keep a left pointer `start` and scan with a right pointer.
  2. Store the most recent index of each character in a hash map.
  3. When you see a character already inside the current window (its last index >= start), jump `start` to just past that previous occurrence instead of shrinking one step at a time.
  4. Track the maximum window length (right - start + 1) as you go.
Last updated: Jun 25, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Implement Top-p (Nucleus) Sampling in NumPy - Amazon (medium)
  • Implement Multi-Head Attention from Scratch in NumPy - Amazon (medium)
  • Detect and Break a Cycle in a Singly Linked List - Amazon (medium)
  • Caesar Cipher with Translation-Table Optimization - Amazon (medium)
  • Minimum Drone Delivery Time on a Ring of Hubs - Amazon (medium)