educative.io

Why do we start again from the previous start but not start+1

indexS1 = start;


Course: Grokking Coding Interview Patterns in Java - Learn Interactively
Lesson: Solution: Minimum Window Subsequence

It’s at line 41 that’s highlighted in the corrected solution


Course: Grokking Coding Interview Patterns in Java - Learn Interactively
Lesson: Solution: Minimum Window Subsequence

1 Like

Hello @Geethika,

Let me help you understand why this step is crucial to finding the minimum window subsequence in a string. As explained in the text above the code widget, the line “indexS1 = start;” is used to update the starting index for the search of the next potential minimum subsequence in the given strings.

After identifying a match between characters of the two strings, it allows the code to efficiently continue the search for the next possible minimum subsequence in the remaining portion of the first string. This update ensures that the search resumes from the next position after the current identified subsequence.

I hope this helps in understanding why we use start instead of start + 1, as this would skip a potential smaller window of a subsequence in the strings.

Please feel free to share any further feedbacks or suggestions, we’d happy to help. Thanks!

Happy learning!


Course: Grokking Coding Interview Patterns in Java - Learn Interactively
Lesson: Solution: Minimum Window Subsequence