Count the number of distinct palindromic substrings in a string

Asked atMorgan Stanley
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Distinguish distinct substrings from occurrences.
  2. 02Explain an Eertree or use expansion plus a set for small bounds.
  3. 03Add each new palindrome once.
  4. 04Handle odd and even centers.
  5. 05State the constraint-driven trade-off.

Reference answer

Then expect these follow-ups

  • How does an Eertree avoid duplicate palindromes?

    Tests: follow-up reasoning

  • When is expand-around-center acceptable?

    Tests: follow-up reasoning

Free to read · better with Enzo

Practice this out loud with Enzo

Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.

Next question