32. Longest Substring Without Repeating Characters
mediumAsked at WorkdayFind the length of the longest substring without repeating characters. Workday uses this for sliding-window fluency — same shape as 'longest unique-employee streak in an audit log'.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Workday loops.
- Glassdoor (2025)— Workday SDE2 phone screen — sliding window staple.
Problem
Given a string s, find the length of the longest substring without repeating characters.
Constraints
0 <= s.length <= 5 * 10^4s consists of English letters, digits, symbols and spaces.
Examples
Example 1
s = "abcabcbb"3Explanation: The answer is 'abc', with the length of 3.
Example 2
s = "bbbbb"1Example 3
s = "pwwkew"3Explanation: The answer is 'wke'.
Approaches
1. Brute force substrings
For each (i, j), check if s[i..j] is unique.
- Time
- O(n^3)
- Space
- O(min(n, alphabet))
// triple loop — quadratic substring count, linear checkTradeoff: Cubic. Won't pass n=50000.
2. Sliding window with last-seen map
Track left edge. For each right, if char was seen >= left, jump left to seen+1. Update best.
- Time
- O(n)
- Space
- O(min(n, alphabet))
function lengthOfLongestSubstring(s) {
const lastSeen = new Map();
let left = 0, best = 0;
for (let right = 0; right < s.length; right++) {
const c = s[right];
if (lastSeen.has(c) && lastSeen.get(c) >= left) {
left = lastSeen.get(c) + 1;
}
lastSeen.set(c, right);
best = Math.max(best, right - left + 1);
}
return best;
}Tradeoff: Single pass. The 'lastSeen >= left' guard prevents the left pointer from going backward when an old duplicate sits outside the window.
Workday-specific tips
Workday wants the O(n) sliding window. The trap is the 'lastSeen >= left' check — without it, you'd jump left backward when an old duplicate is already past. State this invariant before coding.
Common mistakes
- Setting left to lastSeen + 1 unconditionally — moves left backward when duplicate is outside the window.
- Updating best after the inner check breaks but before extending the window.
- Treating substring count as the answer — they want length.
Follow-up questions
An interviewer at Workday may pivot to one of these next:
- Longest Substring with At Most K Distinct (LC 340).
- Minimum Window Substring (LC 76).
- Permutation in String (LC 567).
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why lastSeen >= left and not lastSeen > -1?
Once an index falls behind left, it's no longer in the window. Treating it as 'inside' would force left backward.
Set vs Map?
Map lets you jump left directly to seen+1 in O(1). A Set forces you to walk left one character at a time until you remove the duplicate.
Practice these live with InterviewChamp.AI
Drill Longest Substring Without Repeating Characters and other Workday interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →