Bug Report for longest-substring-without-duplicates
Bug Report for https://neetcode.io/problems/longest-substring-without-duplicates
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
in the problem , we are asked to get the length of a substring with no no repeating chars. index starting form 1 for the length; whereas in the third test case pwwkew, the solution should be 2 casue the third element 'w' is being repeated but the provided expected outcomes is given to be 3.
public int lengthOfLongestSubstring(String s) { HashMap<Character,Integer> hash=new HashMap<>(); int index=0; for( char ch:s.toCharArray()){ if(hash.containsKey(ch))return index; else hash.put(ch,1); index++; } return index-1; }
the above is the copy of my solution.
If I’m mistaken, I’d appreciate it if you could point out where I went wrong so I can correct my understanding.