Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Distinct subsequences

    Distinct subsequences

    Harddynamic programmingstring

    Return how many ways you can pick letters of s (keeping their order) that spell exactly t. Different chosen positions count as different ways.

    Example 1

    Input:  s = "rabbbit", t = "rabbit"
    Output: 3

    Example 2

    Input:  s = "babgbag", t = "bag"
    Output: 5

    Constraints

    • 1 ≤ s.length, t.length ≤ 60
    • Lowercase letters
    • The answer fits in 64 bits

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

    /**
     * @param {string} s
     * @param {string} t
     * @return {long}
     */
    function numDistinct(s, t) {
      
    }
    
    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.