Longest Substring No Repeats
JavaScript
medium
15 mins
Implement a function lengthOfLongestSubstring that takes a string and returns the length of the longest substring without repeating characters.
Input:
- A single string
s(may contain spaces, letters, digits, or symbols)
Output:
- An integer representing the length of the longest substring without repeating characters
Example Inputs & Outputs
// Example 1: Input: "abcabcbb" Output: 3 // "abc" // Example 2: Input: "bbbbb" Output: 1 // "b" // Example 3: Input: "pwwkew" Output: 3 // "wke" // Example 4: Input: "" Output: 0 // Example 5: Input: "aab" Output: 2 // "ab"
Constraints & Edge Cases
- Input string may be empty
- Input string can contain any printable characters
- Repeated characters may appear consecutively or at intervals
- Result must be calculated in optimal time (O(n))
Companies:
microsoft
ola
Solve Similar questions 🔥
Want to upskill? Explore our courses!
Namaste DSA
Master DSA from scratch with numerous problems, and expert guidance.
Namaste React
Wanna dive deep into React and become Frontend Expert? Learn with me now!
Namaste Frontend System Design
The most comprehensive and detailed course for frontend system design.
Namaste Node.js
Wanna dive deep into Node.js? Enroll into `Namaste Node.js` now!
