Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Problem of the day

You are given two strings, * 'str1'* and

A substring is a continuous segment of a string. For example, "bcd" is a substring of "abcd", while "acd" or "cda" are not.

```
Input: ‘str1’ = “abcjklp” , ‘str2’ = “acjkp”.
Output: 3
Explanation: The longest common substring between ‘str1’ and ‘str2’ is “cjk”, of length 3.
```

Detailed explanation

```
wasdijkl
wsdjkl
```

```
3
```

```
The longest common substring is “jkl”, of length 3.
```

```
tyfg
cvbnuty
```

```
2
```

```
The longest common substring is “ty”, of length 2.
```

```
The expected time complexity is O(n*m),
Where ‘n’ and ‘m’ are the lengths of ‘st1’ and ‘str2’ respectively.
```

```
1 <= str1.length <= 1000
1 <= str2.length <= 1000
```