Help Your Friends save 40% on our products


Problem Statement:

Given two strings find length of the longest common substring.

Solution:

If we keep the template discussed in 2-Strings DP in mind, this problem very easily transforms to: for all substrings in the two given strings, find the Longest Common SUFFIX. Why and How ? If the given two strings are str1 = "hackathoncode" and str2 = "marathonsprint", the longest common substring is "athon" which is the longest common SUFFIX for the substrings "hackathon" and "marathon".

Java Code:




This is a Premium content.
Please subscribe to Algorithms course to access the code.




Python Code:




This is a Premium content.
Please subscribe to Algorithms course to access the code.





One of my goals is to make you very comfortable with bottom-up tabulation approach of solving Dynamic Programming. I hope you are getting the hang of it by now.

Instructor:



If you have any feedback, please use this form: https://thealgorists.com/Feedback.



Help Your Friends save 40% on our products

wave