FastPrepFastPrep
Problem Brief

Longest Palindromic Substring

FULLTIMEOA
See Cisco online assessment and hiring insights

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.

1Example 1

Input
s = "babad"
Output
"bab"
Explanation
"aba" is also a valid answer.

2Example 2

Input
s = "cbbd"
Output
"bb"
Explanation
🦊🦊

Constraints

Limits and guarantees your solution can rely on.

  • 1 <= s.length <= 1000
  • s consist of only digits and English letters.
  • public String longestPalindromicSubstring(String s) {
      // write your code here
    }
    
    Input

    s

    "babad"

    Output

    "bab"

    Sign in to submit your solution.