Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Longest palindromic substring

    Longest palindromic substring

    Mediumstringtwo pointersdynamic programming

    Return the longest contiguous part of s that reads the same both ways. If several have the same length, return the one that starts first.

    Example 1

    Input:  s = "babad"
    Output: "bab"

    bab and aba tie; bab starts first.

    Example 2

    Input:  s = "cbbd"
    Output: "bb"

    Constraints

    • 1 ≤ s.length ≤ 1000
    • Lowercase letters and digits

    Submit checks your solution against 9 tests, including hidden ones.

    /**
     * @param {string} s
     * @return {string}
     */
    function longestPalindrome(s) {
      
    }
    
    Sign in to run
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.