As reported: Amazon loop (APAC, Prime Video interviewers, Sept 2025), round 2 with an SDE-2: find all palindromic substrings of a string. The interviewer wanted better than O(n³) and then pushed for less space.
Given a string s, return the number of its substrings that are palindromes. Substrings at different positions count separately even if they are equal.
This is LeetCode 647 — Palindromic Substrings.
Example 1
s = "abc"
Output: 3 "a", "b", "c"
Example 2
s = "aaa"
Output: 6 "a" ×3, "aa" ×2, "aaa"
Constraints: 1 ≤ s.length ≤ 1000; s consists of lowercase English letters.
Code runner format: one line: s as a JSON string. Implement countSubstrings(s); the harness prints the count.