Pretty classic problem but I fumbled the edge cases a bit.
Clarify the problem first: are we finding all palindromic substrings, all palindromic subsequences, or all palindromes in a list of strings? Then choose an efficient algorithm like expanding around centers for substrings (O(n^2) time, O(1) space) or Manacher's algorithm for linear time, and discuss trade-offs.
Pro tip: Amazon interviewers value candidates who ask clarifying questions and discuss edge cases (empty string, single character, case sensitivity, non-alphanumeric characters) before coding. Also, mention that you'd test with examples and consider input size to choose the right approach.
Ask whether the input is a single string or a list, and whether we need all palindromic substrings, subsequences, or just the longest. Confirm if palindromes must be contiguous and if case and non-alphanumeric characters matter.
Outline brute force (check all substrings, O(n^3)), expanding around centers (O(n^2) time, O(1) space), and Manacher's algorithm (O(n) time). Explain trade-offs and choose one based on constraints.
For expanding around centers: iterate over each character and each pair of adjacent characters as centers, expand outward while characters match, and collect palindromes. For Manacher's: preprocess string with separators and compute radii.
Consider empty string, single character, all same characters, and strings with spaces or punctuation. Decide on normalization (e.g., lowercase, remove non-alphanumeric) if needed.
State time and space complexity. Walk through a small example (e.g., 'abba') to verify correctness, and mention potential optimizations or alternative approaches.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.