Class StringInterleaving
java.lang.Object
topics.dynamic.stringinterleaving.StringInterleaving
String Interleaving
Checks if string C is formed by an interleaving of strings A and B. Unlike the Greedy approach, Dynamic Programming guarantees the correct global optimum by exhaustively evaluating and memoizing all valid sub-paths.
The DP State Matrix
dp[i][j] represents whether the first i characters of A
and the first j characters of B can form the first i + j characters of C.
- Time Complexity: O(N * M) - Where N and M are the lengths of strings A and B.
- Space Complexity: O(N * M) - To store the boolean evaluation matrix.
- Author:
- vicegd
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanisInterleaved(String a, String b, String c) Solves the interleaving problem using a bottom-up 2D tabulation.
-
Constructor Details
-
StringInterleaving
public StringInterleaving()
-
-
Method Details
-
isInterleaved
-