Sobes.tech
Junior — Senior

Determining the longest substring with unique characters

livecode

Task condition

Given a string str. The task is to find the maximum length of a contiguous substring in which each character appears only once.

Example 1: Input: str = "abcabcbb" Output: 3 Explanation: The longest substring without repeats is "abc", its length = 3.

Example 2: Input: str = "bbbbb" Output: 1 Explanation: The longest substring without repeats is "b", its length = 1.

Example 3: Input: str = "pwwkew" Output: 3 Explanation: The longest substring without repeats is "wke", its length = 3.

Constraints: 1 ≤ str.length ≤ 50000

class Solution {
    public int lengthOfLongestSubstring(String s) {
        // Implementation
    }
}