Problem · Sliding Window

Longest Substring Without Repeating Characters

Learn this problem
MediumOmnissaONSITE INTERVIEW

Problem statement

A quick note: this problem is backed by a real Omnissa onsite interview report that directly named Longest Substring Without Repeating Characters. The report did not include an exact function interface, examples, constraints, or character-set rules. The core task match is about 95%.

Given a string s, return the length of the longest substring that contains no repeated characters.

Interview Follow-up

This was part of a rapid-fire three-problem round in which the candidate presented brute-force, improved, and optimal approaches and wrote working code for each problem.

Function

lengthOfLongestSubstring(s: String) → int

Examples

Example 1

s = "abcabcbb"return = 3

The longest substrings without repeated characters include "abc", with length 3.

Example 2

s = "bbbbb"return = 1

Every valid substring without repeats has length 1.

More Omnissa problems

drafts saved locally
public int lengthOfLongestSubstring(String s) {
  // write your code here
}
s"abcabcbb"
expected3
checking account