All Distinct Palindromic Substrings
Problem statement
Given a string s, return all of its palindromic substrings.
A substring is one or more letters that sit next to each other in s. A palindrome reads the same forward and backward, so every single letter is a palindrome.
If the same palindrome appears more than once in s, include it only once. Return the palindromes sorted in dictionary (lexicographic) order.
Function
allPalindromicSubstrings(s: String) → List<String>Examples
Example 1
s = "level"return = ["e","eve","l","level","v"]The palindromes are "l" (twice), "e" (twice), "v", "eve" and "level". Each different one is listed once, in dictionary order.
Example 2
s = "noon"return = ["n","noon","o","oo"]The single letters "n" and "o" are palindromes. So are "oo" and the whole string "noon", which both have even length.
Example 3
s = "dash"return = ["a","d","h","s"]No two neighboring letters match and no letter repeats, so only the four single letters are palindromes. In dictionary order they are "a", "d", "h", "s".
Constraints
1 <= s.length <= 1000sconsists of lowercase English letters.