

If “str1” = “abcjklp” and “str2” = “acjkp” then the output will be 3.
Explanation : The longest common substring is “cjk” which is of length 3.
The first line contains an integer ‘T’ which denotes the number of test cases or queries to be run. Then the test cases are as follows.
The first and only line of each test case contains two space-separated strings str1 and str2, respectively.
For each test case, print the length of the longest common substring among the two strings.
Print the output of each test case in a separate line.
1 <= T <= 100
1 <= |str1|, |str2| <= 100
where ‘T’ is the number of test cases and |str| is the length of the string str.
The basic idea is to start slicing the first string into the substring and match those substrings in the second string.
The basic idea is to recursively try and match characters from str1 to characters of str2 and vice versa also.
Let us observe the recursion tree for the case where str1 = “xyz” and str2 = “xbyz”

The repetition of such sub-problems suggests that we can use dynamic programming to optimize our approach.
The key idea behind a dynamic programming approach is to use memoization, i.e. we’ll save the result of our sub-problem in a matrix so that it can be used later on.
Let dp[ i ][ j ] be our dynamic programming matrix to store the length of longest common substring of string “str1” and string “str2”.
The idea is to find the length of the longest common suffix for all substrings of both strings and store these lengths in a table (LCSuff) using the relation :
LCSuff[i][j] = | LCSuff[i-1][j-1] + 1 (if str1[i-1] == str2[j-1])
| 0 (otherwise)
where,
0 <= i – 1 < N, where N is the length of string str1
0 <= j – 1 < M, where M is the length of string str2
result = max(result, LCSuff[i][j])
Frog Jump
Frog Jump
Frog Jump
Frog Jump
Frog Jump
Reshape the Matrix
Set Matrix Zeros
Set Matrix Zeros
Set Matrix Zeros
Set Matrix Zeros
Set Matrix Zeros
Set Matrix Zeros
Shortest Common Supersequence
Shortest Common Supersequence
Shortest Common Supersequence
Shortest Common Supersequence
Shortest Common Supersequence
Shortest Common Supersequence
Shortest Common Supersequence
Stock Span
Stock Span
Stock Span