FastPrepAll Distinct Palindromic Substrings
Problems/All Distinct Palindromic Substrings

All Distinct Palindromic Substrings

DoorDash logoDoorDash● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: A 2025 report from a DoorDash machine learning engineer onsite lists one coding round, about finding the palindromes inside a string. That one line is all it gives.

The report does not say whether a palindrome that appears twice counts twice, what order to use, or how long the string can be. Here, each different palindrome is listed once, in dictionary order, and the string has 1 to 1000 lowercase letters.

The judged task matches the report at about 85%.

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 <= 1000
  • s consists of lowercase English letters.

More DoorDash problems

  • Customer Bootstrap APIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Dasher Pay with Store Waits and Peak HoursPHONE SCREEN · Seen Nov 2026
  • Random Dasher Set OperationsONSITE INTERVIEW · Seen Nov 2026
All DoorDash interview questionsSee DoorDash hiring insights
Saved
public List<String> allPalindromicSubstrings(String s) {
    // Write your code here.
}
Checking account…