The complexity of `thePath.indexOf(potentialParent)` is *O(max(n, m))* where *n* and *m* are the path lengths assuming that indexOf does not employ a naïve algorithm. This is because it will consider substrings that do not start at index 0, which are not interesting in this case. `thePath.lastIndexOf(portentialParent, 0)` forces the algorithm to only consider substrings that start at index 0.