Removing Arrays.fill() or for loops, added longest common substring#2027
Removing Arrays.fill() or for loops, added longest common substring#2027icoder211 wants to merge 10 commits intoTheAlgorithms:masterfrom
Conversation
…fills the array with 0s As pointed out by @prashantdoshi28
Added Longest Common substring of two strings
Revert "Added Longest Common substring of two strings"
| @@ -0,0 +1,27 @@ | |||
| public class LongestCommonSubstring { | |||
There was a problem hiding this comment.
Can you please add problem statement and other relevant info.
| + 1]; // stores the value of distance from all the possible path form the source | ||
| // vertex to destination vertex | ||
| Arrays.fill(DistanceMatrix, 0); | ||
| // here the distanceMatrix is initialized by 0s b default upon initialization with new keyword |
There was a problem hiding this comment.
Good, thanks for considering this 👍
|
Hey @icoder211 , what I meant by add relevant info is that add comment in code explaining problem and document your code so anyone from watching your code, can understand why you did what you did. |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
Please reopen this pull request once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to seek help from our Gitter or ping one of the reviewers. Thank you for your contributions! |
Removed Arrays.fill() because new keyword initializes a 2D array of int's with 0s, as pointed out by @prashantdoshi28
The longest common substring problem:
Given two strings, "S" and "T", find the length of the longest common substring between the two strings
A "substring" of a string "S" is that string, with any number of characters (0 or more) deleted from the front of S, and any number of characters (0 or more) deleted from the end of S.
A common substring of two strings S and T is any substring s of S and substring t of T, such that s = t.
Output the length longest such common substring.
Sample test case:
S = "abbaf"
T = "abcdef"
Sample output:
2
Explanation:
The common substrings are:
"ab"
"a"
"b"
"f"
The longest among them is "ab", of length 2.
References
Checklist:
Fixes: #{$ISSUE_NO}.