Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

s1 =
s2 =
s3 =

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

DP on prefixes: decide whether next char of s3 comes from s1 or s2.

Approach

Let dp[i][j] be whether s1[:i] and s2[:j] can form s3[:i+j]. Transition uses last char from s1 or s2. Use 1D rolling DP over j.

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

Idea

DP on prefixes: decide whether next char of s3 comes from s1 or s2.

Approach

Let dp[i][j] be whether s1[:i] and s2[:j] can form s3[:i+j]. Transition uses last char from s1 or s2. Use 1D rolling DP over j.

Code
Loading...
Complexity
Time: O(|s1||s2|)
Space: O(|s2|)