leetcode icon indicating copy to clipboard operation
leetcode copied to clipboard

Bug Report for longest-substring-without-duplicates

Open anshul-rohilla4 opened this issue 2 months ago • 0 comments

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.

anshul-rohilla4 avatar Oct 06 '25 18:10 anshul-rohilla4