190. Longest Substring Without Repeating Characters (Brute)

EasyStringString

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

This is the easy (brute-force) variant: implement an O(n²) or better solution.

A substring is a contiguous sequence of characters within the string.

Input: A single string s.

Output: An integer — the length of the longest substring with all unique characters.

Examples

Example 1
Input: abcabcbb
Output: 3
Explanation: The answer is 'abc' with length 3.
Example 2
Input: bbbbb
Output: 1
Explanation: Only one unique character; best window is length 1.
Example 3
Input: pwwkew
Output: 3
Explanation: Answer is 'wke' (length 3).

Constraints

Asked by

InfosysAdobeIBMCognizantBloombergOracle
Solve this problem in the editor →