Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Longest Unique Message Substring

MediumPython00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the Python screen.

The question is on your right: Longest Unique Message Substring. Read through the requirements first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

You need to log in / sign up to run or submit.

Problem

In Providence messaging and note-entry surfaces, repeated characters can appear in free-text input. Write a function that returns the length of the longest substring in a string s that contains no repeated characters.

Formal Specification

  • Input: a string s
  • Output: an integer representing the maximum length of any contiguous substring of s with all unique characters

A substring must be contiguous. The function should run efficiently for large inputs.

Constraints

  • 0 <= len(s) <= 10^5
  • s consists of printable characters, including spaces and symbols
  • Return the length of the longest valid substring

Function Signature

def length_of_longest_substring(s):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output