Junilu Lacar wrote:If I remember my Big O correctly, since markerLength is a constant, doesn't that make O(input.length * markerLength) the same as O(input.length) anyway?
Yes, if you treat markerLength as constant. But they
do change the markerLength between part 1 and 2. The new value isn't that big, really - but in some of their problems, they make part 2 a much more performance-intensive version of part 1, so you never know if one of the values you thought was constant actually turns out to matter quite a bit. This is a more general issue with big-O notation - people don't always realize (or agree) which parameters might become significant later.
Note that for Stephan's regex solution, the length of the regex you need is O(markerLength ^ 2). Still manageable for markerLength=14, but it's growing.
Though I may be missing a way to simplify.