Can't indexS1 be set to end instead of start?

At the very end why set indexS1 to start? The substring between start and end is guaranteed to not contain the str2 chars in order otherwise it would be a smaller subsequence than the one w just found - a contradiction. So we can safely jump indexS1 to end.


Course: https://www.educative.io/courses/grokking-coding-interview-patterns-cpp
Lesson: Solution: Minimum Window Subsequence - Grokking Coding Interview Patterns in C++

2 Likes

Hi @Enki
We can not set indexS1 to end instead of start. It does not work for some cases like if the string1 is equal to azstaszaztf and string2 is equal to saz if we run our code with indexS1 = end, at the very end of the code. It will return stasz instead of saz, but if you change indexS1 to start it will give you the desired output. That’s why we can not change indexS1 to end at the very end of the code.
Happy learning :slightly_smiling_face:

2 Likes

@Enki @Ahmar_Tabassum May be we can set indexS1 to the position in which second char in the sequence is found. May not make much difference, but we can do so :wink:.

1 Like