Core Idea
A valid window contains no repeated value. When a duplicate appears, move the left end until the duplicate is removed.
Algorithm
Use a frequency map or last-seen positions while scanning the right endpoint. After restoring validity, update the best window length.
Common Mistakes
Do not reset the whole window after a duplicate; only move the left boundary as far as needed. This keeps the total work linear.