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

    Longest common subsequence

    Mediumdynamic programmingstring

    A subsequence keeps characters in order but not necessarily adjacent (ace from abcde). Return the length of the longest subsequence common to a and b.

    Example 1

    Input:  a = "abcde", b = "ace"
    Output: 3

    Example 2

    Input:  a = "abc", b = "def"
    Output: 0

    Constraints

    • 1 ≤ a.length, b.length ≤ 1000
    • Lowercase English letters

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

    /**
     * @param {string} a
     * @param {string} b
     * @return {int}
     */
    function longestCommonSubsequence(a, b) {
      
    }
    
    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.