Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

s =
t =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Count how many subsequences of s equal t.

Approach

DP on prefixes: dp[j] = number of ways to form t[:j] from processed prefix of s. For each char in s, update j backwards: if s[i-1]==t[j-1], add ways for t[:j-1].

Why it works

When chars match, you can either use this s char to match t[j-1] or skip it; backward iteration prevents double counting.

Code
Loading...
Complexity
Time: O(|s||t|)
Space: O(|t|)
Solution
Updated: 2026-02-23

Idea

Count how many subsequences of s equal t.

Approach

DP on prefixes: dp[j] = number of ways to form t[:j] from processed prefix of s. For each char in s, update j backwards: if s[i-1]==t[j-1], add ways for t[:j-1].

Why it works

When chars match, you can either use this s char to match t[j-1] or skip it; backward iteration prevents double counting.

Code
Loading...
Complexity
Time: O(|s||t|)
Space: O(|t|)