educative.io

Educative

Unused code, why is it here?

This section of code:

       if (indexS2 == -1) {
        flag = indexS2;
        indexS2 = sizeStr2 - 1;
      }

Starting on line 21 in the final example is never executed. Nor is the related on lines 28-31… What is the goal of this code and how could we create a test case to exercise that code?


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

Hello Chris,

During step-by-step construction of the solution, indexS2 goes out of range i.e., -1. In order to avoid error, we have added these checks (Lines: 23-26 & 30-33), but in the last step, we set indexS2 to 0 which fixes this issue and hence there is no need for these checks anymore. Hence, these checks will be removed from the final step in our course very soon. However, they are needed in the initial steps to avoid error so they will stay in the initial steps as it is.