Proficient Level

Implement the method countPalindromicSubstrings that counts all palindromic substrings.

Count every contiguous substring that reads the same forward and backward.

The task is designed to test careful handling of edge cases, not only the most common input.

  • Single characters count as palindromic substrings.
  • Substrings with the same text but different positions are counted separately.
  • Comparison is case-sensitive.

Example 1

Input
s (string) = abc
Returns (int) 3

Example 2

Input
s (string) = aaa
Returns (int) 6

Example 3

Input
s (string) = abccba
Returns (int) 9

Expand around every possible center, including centers between two characters, and count matching expansions.

Ready to test your solutionRun Code checks your solution against the test cases.Shift + Enter to run

Notifications

Updates are enabled for this browser.

Receive new tutorials, articles and learning resources. You can turn updates off anytime.

Test browser code

Use this code in admin to send a test notification to this browser.