What do you think of this solution?

So I found a different solution, and wondering if there’s any reason this is an unreliable way to solve something like this.

I created an empty list called “checklist,” made the comparison of list indexes == instead of !=, and appended a placeholder item to “checklist” every time it was True. Then, to determine True or False, I compared len(checklist) to len(lst1), because theoretically if every comparison was equal, checklist would have the same amount of items (from being appended).

The method would take a complete iteration of the list, and would require an extra step to append the list, which is itself a data structure. Then the final comparison is an added step. That would amount to,

2 * N + 1 

steps, and a data structure.

The method that returns False on the first non-match uses only that many steps, and short-circuits the function. The maximum number of steps will be N.

1 Like