Find the longest substring that reads the same forwards and backwards. Expand around centres: every palindrome has a centre that's either a single character (odd length) or between two characters (even length). There are centres, and expanding each costs up to , giving overall in extra space.
Implement longest_palindrome(s), returning the first-occurring longest one on ties ("" for empty input). Then implement count_palindromic_substrings(s): how many substrings (counted by position) are palindromes.