Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
"aabccbbdef" is a good example that will trigger the edge case. As mentioned by ...

Bharpur Singh

Sep 10, 2022

"aabccbbdef" is a good example that will trigger the edge case. As mentioned by Eric as we encounter second b windowEnd will be at 5 and windowStart at second b i.e. 3 position. As soon as it encounter third b in the string it will update windowStart to 6 again. Hence, windowStart = map[rightChar] +1 will produce correct result. In order to test use "aabccbdef" string. I removed b at 6th place. Hence, when we update windowStart to point at 3 it will not be updated. Correct answer for this is 5, but due to map[rightChar] +1 we will get 6. which shows why we use Math.max().

0

0

Comments
Comments

On this page