class NoRepeatSubstring {
public static int findLength(String str) {
int windowStart = 0, maxLength = 0;
boolean hasElement = false;
Set<Character> uniqueCaharacters = new HashSet<>();
for(int windowEnd = 0; windowEnd < str.length(); windowEnd++){
hasElement = !uniqueCaharacters.add(str.charAt(windowEnd));
while(hasElement && windowStart < windowEnd){
uniqueCaharacters.remove(str.charAt(windowStart));
windowStart++;
}
maxLength = Math.max(maxLength, windowEnd - windowStart + 1);
}
return maxLength;
}
}