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

0% completed

Vote For New Content
Why can't you insert rightChar into the map first and then update widowStart, su...

Yogi Paturu

Dec 18, 2021

Why can't you insert rightChar into the map first and then update widowStart, such that it's the max of windowStart and the index of rightChar? It seems to be equivalent to me, but swapping the order of the if condition and updating the charIndexMap doesn't work

Anyone have any insight into this?

0

0

Comments
Comments
D
David Gohberg4 years ago

inserting the char first will override the previous location of the character. we want the old location to shift the window. after the window start is shifted, we insert to the map and update char with its ew location

N
Nick 4 years ago

David I'm not sure if this is the case. Geeksforgeeks has this problem that you can solve and adding the right character into the map first, you still pass all their test cases.

Solution below: def longestSubstrDistinctChars(self, S):

code here

windowStart = 0 longe...

N
Ngân Nguyễn3 years ago

I didn't really get the window " In the current window, ...." . Can anyone explain that? Tks in advance.

On this page