Problem · String

Longest Palindromic Substring

Learn this problem
MediumCiscoFULLTIMEOA
See Cisco hiring insights

Problem statement

Heads up! Original problem is from LeetCode 5. Note that in the original problem, a single character is also considered palindromic, so before printing, you just need to check if the length of the longest palindromic substring is 1. Otherwise, follow the original LeetCode problem as is.

Given a String s, return the longest palindromic substring in s.

Function

longestPalindromicSubstring(s: String) → String

Examples

Example 1

s = "babad"return = "bab"
"aba" is also a valid answer.

Example 2

s = "cbbd"return = "bb"
🦊🦊

Constraints

  • 1 <= s.length <= 1000
  • s consist of only digits and English letters.
  • More Cisco problems

    drafts saved locally
    public String longestPalindromicSubstring(String s) {
      // write your code here
    }
    
    s"babad"
    expected"bab"
    checking account