Longest Palindromic Substring LeetCode Be Crazy

Strive not to be a success, but rather to be of value. — Albert Einstein

Let me start off by saying Holy Shit. This one is now very well understood. Rule number one to “Cracking the code”… Start off with a naive approach. I spent a meaningful amount of my life trying to make this code O(nlogn) vs the very (simple?) O(n²) solution; I will be going over both in the lines below.

So, take a second and think about what elements, variables, function… this algorithm will need.

We will need to check all possible inner string combinations, so that means we will need two pointers, one to represent a start point and another the end;

So without further ado, The Smart Way.

This answer was “stolen” from algoexpert.io, for a better explanation, go sign up, its well worth it.