easyM Mixed TopicsPattern: String Operations
Palindrome Substring Enumeration Solution
Problem Statement
Given a string `sequence` of length `n`, find and return all unique substrings that are palindromes. The order of the substrings in the output should match their first occurrence in the input string `sequence`. A substring `sub` is considered a palindrome if `sub` equals its reverse (`sub` spelled backwards).
Examples
Example 1:
Input:abba
Output:["a","b","bb","abba"]
Explanation: All unique substrings that are palindromes in order of their appearance
Example 2:
Input:abc
Output:["a","b","c"]
Explanation: All unique substrings that are palindromes in order of their appearance
Constraints
- The input string S will not be empty.
- The input string S will not contain any repeated substrings.
Time: O(n^2) Space: O(n)
Analyze constraints and compute optimal solutions step-by-step.
Run, Test & Submit Code
Ready to practice this challenge? Launch our interactive compilation environment with compiler validation.
Solve on Interactive WorkspaceTested Solutions
No solution code is currently loaded.
Complete this code in the workspace editor.
