O(n)

similar to longest palindromic substring method