Walk me through how a variable-size sliding window finds the longest substring without repeating characters, and why it runs in linear time.

technical-conceptual · Mid level · software-engineering

What the interviewer is really asking

Tests whether the candidate can drive a concrete variable-window algorithm end to end, justify the O(n) bound by amortized pointer movement, and pick the right auxiliary structure.

What to say

What to avoid

Example answers

Strong: I used this to find the longest run of distinct session events in a stream. I kept a map of character to last-seen index so on a repeat I jumped left straight past the previous occurrence rather than stepping one at a time, and I tracked the best length as I went. One pass, linear, no re-scanning.

Weak: I'd check every substring and test whether it has all unique characters, then take the longest one.

Want questions matched to your role? Paste a job title, job description, or CV and get a personalized set, or go Pro to unlock the full bank.