Skip to content

Removing Arrays.fill() or for loops, added longest common substring #2027

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 10 commits into from

Conversation

icoder211
Copy link

@icoder211 icoder211 commented Nov 12, 2020

  1. Removed Arrays.fill() because new keyword initializes a 2D array of int's with 0s, as pointed out by @prashantdoshi28

  2. 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.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

References

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Java files are placed inside an existing directory.
  • All filenames are in all uppercase characters with no spaces or dashes.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@icoder211 icoder211 changed the title Removing Arrays.fill() or for loops Removing Arrays.fill() or for loops, added longest common substring Nov 13, 2020
@@ -0,0 +1,27 @@
public class LongestCommonSubstring {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add problem statement and other relevant info.

@@ -14,7 +14,7 @@ public FloydWarshall(int numberofvertices) {
[numberofvertices
+ 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, thanks for considering this 👍

@prashantdoshi28
Copy link

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.

@github-actions
Copy link

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.

@github-actions
Copy link

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!

@github-actions github-actions bot added the stale label Sep 26, 2021
@github-actions github-actions bot closed this Sep 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants