InferenceAI

Enter at least two characters to search.

Start free

Interleaving Strings

hardDynamic Programming40 min50 XP

Return True if c is an interleaving of a and b: it uses all characters of both, keeping each string's internal order.

Examples

EXAMPLE WALKTHROUGHpossible

A guided view of the published example, not a trace of your code.

INPUT["aabcc","dbbca","aadbbcbcac"]
TASKinterleaving_strings()
EXPECTED OUTPUTtrue

Start with the input values shown in this example.

Example 1 of 3

Input: a = "aabcc", b = "dbbca", c = "aadbbcbcac"

Output: true

Explanation: possible

Input: a = "aabcc", b = "dbbca", c = "aadbbbaccc"

Output: false

Explanation: impossible

Input: a = "", b = "", c = ""

Output: true

Explanation: all empty

Hint 1

dp[i][j] = c[:i + j] is an interleaving of a[:i] and b[:j].

Topics

DSADynamic ProgrammingPython