Mark As Completed Discussion

Coming to the main problem, let's find a brute force method to find the longest palindromic substring.

For the brute force method, the logic is that you'll find all substrings. Let's say we have the string "Maham" again. You'd try to generate all substrings in it.

Brute Force

After obtaining all the substrings, what we'll do is reverse each substring, and check whether it's palindromic or not. This way we'll naturally keep the longest palindromic one.

Brute Force