3 ms·
> 'finding if a string is a substring of another string' Unless you mean using a "substring" function or regexes... coming up with the naïve O(n^2) algorithm i
by Tainnor 2y ago
> 'finding if a string is a substring of another string'
Unless you mean using a "substring" function or regexes... coming up with the naïve O(n^2) algorithm is indeed easy, but finding a fast algorithm like KMP is, I would say, non-trivial?
For the "second-largest number in array" it's rather easy to come up with an O(n) algorithm, so I would consider the two cases to be different.
- ltbarcly3 2y agoI mean N^2!