⭐Longest Palindromic Substring
Thoughts
It says substring so probably I need a sliding window.
It also says palindrome so probably I need the two-pointer.
But then using both of these will make it a brute force solution.
I'll generate every substring and check for palindrome using the two-pointer approach.
I'll just go ahead and code the brute force one once.
28:00 Ok so the solution that I assumed to be a brute force one got accepted as a valid solution. I'll paste it here and see what the actual solution is.
31:00 Watching Neet Code's Explanation
What's the time Complexity of my current solution?
Neet Code is pretty lazy with his code. Don't pick his ways. Be strong. Be hard working.
42:00 Video Watched. Start Coding.
51:00 Coded and got accepted. I'll paste the code here.
53:00 Done. I'll add this method to the formula list.
Brute Force
Time Complexity: O(n3)
Where isPalindrome(str) takes O(n) time and generating all the substrings take O(n2) time.
Space Complexity: O(n) for the result.
Efficient Solution
Time Complexity: O(n2)
Space Complexity: O(n) for the result
Logic: Assume each letter as a centre of a palindrome and expand outward while checking if it is a palindrome.
Edge Case: Even Length palindrome.
Last updated