Given a string, find the length of the longest substring that contains no repeating characters. A substring is a contiguous sequence of characters within the string. Return 0 for null or empty input.
Examples:
Input: str = 'abcabcbb'
Output: 3
Explanation: The longest substring without repeating characters is 'abc' with length 3
Input: str = 'bbbbb'
Output: 1
Explanation: The longest substring is 'b' with length 1
Input: str = 'pwwkew'
Output: 3
Explanation: The longest substring is 'wke' with length 3
Input: str = ''
Output: 0
Explanation: Empty string returns 0
Input: str = 'abcdef'
Output: 6
Explanation: All characters are unique, so the entire string is the answer
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay July 2026
Contest runs July 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.