FastPrepLongest Palindromic Substring

Longest Palindromic Substring

Cisco logoCisco● MediumFULLTIMEOA
Learn

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

See Cisco hiring insights
public String longestPalindromicSubstring(String s) {
  // write your code here
}
s"babad"
expected"bab"
Checking account…