Distinct Palindromic Substrings
CitadelOnline assessmentMedium
Given a string s of lowercase letters, find its distinct palindromic substrings. Implement distinct_palindromes(s), which returns them as a list of strings sorted in lexicographic order.
Part 1: Distinct palindromic substrings
Given s, return every distinct palindromic substring once, sorted in lexicographic order. A substring is a run of consecutive characters of s, and a palindrome reads the same forwards and backwards. A palindrome that occurs at several positions is listed once.
- Example 1
- s
"abaab"- Output
["a","aa","aba","b","baab"]
Why: Palindromic substrings of
abaabarea,b,aa,abaandbaab.aoccurs three times andbtwice, but each distinct value appears once, in sorted order.
Constraints
1 <= len(s) <= 1000'a' <= s[i] <= 'z'
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.