0% completed
windowStart = Math.max(windowStart, charIndexMap.get(rightChar) + 1);Any...
Pratik
Feb 28, 2022
windowStart = Math.max(windowStart, charIndexMap.get(rightChar) + 1);
Any example of this happening? I cant think of an example where windowStart is greater than rightChar ?
Please elaborate.
2
0
Comments
Eric C4 years ago
Imagine you have the string "aabccbbdef". The longest substring with distinct characters in this case would be "bdef" length of 4. We need to take the max of 'windowStart' and 'charIndexMap.get(rightChar) + 1' because when we get to the second 'b' where windowEnd = 5, w...
Joshua Causey4 years ago
Hey I'm really trying to understand this edge case. Using the string "aabccbbdef" I get the correct output of 4 using both of the below assignments for windowStart
windowStart = map[rightChar] +1 windowStart = Math.max(windowSum, map[rightChar] + 1
Have an edge case e...
linochoa11690 3 years ago
At first it was difficult to understand for me at first until I traced the code. The way I understand it is, if you updated windowStart because you found a duplicate char but still had old values in the hashmap pointing to other chars before windowStart you wouldn't wan...
On this page