Problem intuition
The naive version grows a substring from every starting point until a repeat appears.
The optimal solution treats the substring as a sliding window and shrinks it only when a repeated character breaks validity.
Java solution ladder
The solutions below are ordered from least optimal to most optimal, so you can see the improvement path instead of only the final answer.