Skip to content

#3946 updated .md #3971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
id: Interleaving-Strings
title: Interleaving Strings
sidebar_label: Interleaving Strings
tags:
tags:
- Dynamic Programming
- Strings
- Interleaving String
---

## Problem Description

| Problem Statement | Solution Link | LeetCode Profile |
| Problem Statement | Solution Link | LeetCode Profile |
| :------------------------------------------------------ | :------------------------------------------------------------------------- | :------------------------------------------------------ |
| [Interleaving-Strings](https://leetcode.com/problems/Interleaving-Strings/description/) | [Interleaving-Strings Solution on LeetCode](https://leetcode.com/problems/Interleaving-Strings/solutions/) | [Nikita Saini](https://leetcode.com/u/Saini_Nikita/) |

Expand All @@ -30,8 +30,15 @@ The interleaving is `s1 + t1 + s2 + t2 + s3 + t3 + ...` or `t1 + s1 + t2 + s2 +

### Examples


#### Example 1:
**Input:** `s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc"`
**Output:** `false`
**Explanation:**
Notice how it is impossible to interleave `s2` with any other string to obtain `s3`.


#### Example 2:
**Input:** `s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"`
**Output:** `true`
**Explanation:**
Expand All @@ -40,12 +47,8 @@ Split `s1` into `s1 = "aa" + "bc" + "c"`, and `s2` into `s2 = "dbbc" + "a"`.
Interleaving the two splits, we get `"aa" + "dbbc" + "bc" + "a" + "c" = "aadbbcbcac"`.
Since `s3` can be obtained by interleaving `s1` and `s2`, we return `true`.

#### Example 2:

**Input:** `s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc"`
**Output:** `false`
**Explanation:**
Notice how it is impossible to interleave `s2` with any other string to obtain `s3`.


#### Example 3:

Expand All @@ -54,6 +57,7 @@ Notice how it is impossible to interleave `s2` with any other string to obtain `


### Constraints

- $0 \leq \text{s1.length}, \text{s2.length} \leq 100$
- $0 \leq \text{s3.length} \leq 200$
- $\text{s1}$, $\text{s2}$, and $\text{s3}$ consist of lowercase English letters.$
Expand Down Expand Up @@ -100,6 +104,7 @@ class Solution:
```

## Solution in Java

```java
class Solution {
public boolean isInterleave(String s1, String s2, String s3) {
Expand Down Expand Up @@ -129,7 +134,9 @@ class Solution {
}
```


## Solution in C++

```cpp
class Solution {
public:
Expand Down Expand Up @@ -193,6 +200,7 @@ bool isInterleave(char* s1, char* s2, char* s3) {
}
```


## Solution in JavaScript
```js
var isInterleave = function(s1, s2, s3) {
Expand Down Expand Up @@ -221,5 +229,6 @@ var isInterleave = function(s1, s2, s3) {
};
```


## Conclusion
By utilizing dynamic programming, we can efficiently determine whether a given string `s3` is an interleaving of two other strings `s1` and `s2`. This approach ensures that we consider all possible ways to form `s3` from `s1` and `s2` while adhering to the interleaving constraints.
Loading